⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 windowlogin.java

📁 宿舍管理系统(包括论文): 该系统是用JAVA语言编写的学生公寓管理系统,本系统在研制开发过程中
💻 JAVA
字号:
import java.awt.*;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.DefaultMutableTreeNode;

import java.awt.event.*;
import java.sql.*;

class WindowLogin extends JFrame implements ActionListener
{
	Connection con=null;
	Statement sta=null;
	JLabel l,l1,l2;
	JButton b1,b2;
	JTextField tf1;
	JPasswordField tf2;
	TextField ff;
	String conURL="jdbc:mysql://localhost/login?user=root&password=root";
	ResultSet rs;
	WindowLogin()
	{
		super("系统登入界面"); 
		setBounds(150,150,400,300);
		setLayout(null);
		this.setResizable(false);
		l=new JLabel();
		l.setText( "欢迎登陆宿舍信息管理系统" );
		
		l.setFont( new Font("Dialog", 1, 25));
		l.setForeground( new Color(255, 144, 85 ) );
		l.setHorizontalAlignment(SwingConstants.CENTER);
		l.setBounds(20,20,350,40);
		add(l);
		
		l1=new JLabel("用户名:");
		l1.setForeground(Color.black);
		l1.setFont(new Font("Dialog", 1, 20));
		l1.setBounds(70,90,80,30);
		add(l1);
		
		l2=new JLabel("密  码:");
		l2.setForeground(Color.black);
		l2.setFont(new Font("Dialog", 1, 20));
		l2.setBounds(70,120,80,30);
		add(l2);
		tf1=new JTextField(20);
		tf1.setBounds(150,90,140,30);
		add(tf1);
		tf2=new JPasswordField();
		tf2.setBounds(150,120,140,30);
        add(tf2);
		b1=new JButton("登陆");
		b1.setBounds(70,160,100,40);
		add(b1);
		b2=new JButton("重置");
		b2.setBounds(190,160,100,40);
		add(b2);
		b1.addActionListener(this);
		b2.addActionListener(this);
		ConSql();
		setVisible(true);
	}
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==b1)
		{
			LogIn();
		}
		else if(e.getSource()==b2)
		{
			tf1.setText("");
			tf2.setText("");
		}
	}
	public void LogIn()
	{
		String str1=tf1.getText().trim();
		String str2=tf2.getText().trim();
		try{
			con=DriverManager.getConnection(conURL);
			rs=sta.executeQuery("select * from login");
			while(rs.next())
			{
				String user1=rs.getString("user").trim();
//				String pwd=rs.getString("pwd").trim();
				if(user1.equals(str1))
				{
					String pwd1=rs.getString("pwd").trim();
					if(pwd1.equals(str2))
					{
					    System.out.println("用户登入成功!");
					    rs.close();
					    sta.close();
					    con.close();
					    this.dispose();
					    new Window();
					    break;
					}
					else{
						System.out.println("密码错误");
						new JOptionPane().showMessageDialog(null, "密码错误或者用户不存在。");
						break;
					}
				}
				
				
			}
		}
		catch(SQLException e1)
		{
			e1.printStackTrace();
		}
	}
		
	
	public void ConSql()
	{
		try{
			Class.forName("com.mysql.jdbc.Driver");
			con=DriverManager.getConnection(conURL);
			sta=con.createStatement();
		}
		catch(ClassNotFoundException e){
			e.printStackTrace();
		}
		catch(SQLException e){
			e.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -