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

📄 userlogin.java

📁 基于目前许多中小型公司, 机关,中小学校,大学院系等都有自己的图书库, 供内部人员借阅。传统的手工登记办法
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class UserLogin extends JFrame implements ActionListener
{
	
	MainWindow mainFrame;
	JLabel UserLabel,PasswordLabel;
	JTextField UserTextField;
	JPasswordField PasswordTextField;
	JButton YesBtn,CancelBtn;
	Container c;
	ResultSet rs;
	public UserLogin(MainWindow mainFrame)
	{
		super("用户登录");
		this.mainFrame=mainFrame;
		Container c=this.getContentPane();
    	c.setLayout(null);
    
    	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	UserLabel=new JLabel("用户名:");
    	PasswordLabel=new JLabel("密码:");
    	UserTextField=new JTextField(20);;
    	PasswordTextField=new JPasswordField(20);
    	YesBtn=new JButton("确定");
    	CancelBtn=new JButton("取消");
    	JPanel p1, p2,p3,p23;
    	p1=new JPanel();
    
    	p1.setLayout(new BoxLayout(p1,BoxLayout.X_AXIS));
    	p1.add(Box.createHorizontalStrut(60));
    	p1.add(YesBtn);
    	p1.add(Box.createHorizontalStrut(40));
    	p1.add(CancelBtn);
    	p1.add(Box.createHorizontalStrut(60));
    	YesBtn.addActionListener(this);
    	CancelBtn.addActionListener(this);
    	p2=new JPanel(new GridLayout(2,1,10,10));
    
    	p3=new JPanel(new GridLayout(2,1,10,10));
    
    	p23=new JPanel();
    
    	p23.setLayout(new BoxLayout(p23,BoxLayout.X_AXIS));
    	p23.add(Box.createHorizontalStrut(20));
    	p23.add(p2);
    	p23.add(Box.createHorizontalStrut(30));
    	p23.add(p3);
    	p23.add(Box.createHorizontalStrut(15));
    	p2.add(UserLabel);
    	p2.add(PasswordLabel);
    	p3.add(UserTextField);
    	p3.add(PasswordTextField);
    	p23.setBounds(0,10,300,70);
    	p1.setBounds(0,90,300,50);
    	c.add(p23);
    	c.add(p1);
    	this.setBounds(320,180,300,180);
    	this.setVisible(true);
	}
	public void actionPerformed(ActionEvent e)
	{
		Connection con;
    	PreparedStatement sql;
        ResultSet rs;
        boolean boo=false;
		if(e.getSource()==CancelBtn)
		{
			//mainFrame.setEnable("else");
			this.dispose();
		}
		else
		{
			String password=PasswordTextField.getText();
			String name=UserTextField.getText();
			if(name.trim().equals(""))
			{
				JOptionPane.showMessageDialog(null,"用户名不可为空!");
				return;
			}
			if(password.equals(""))
			{
				JOptionPane.showMessageDialog(null,"密码不可为空!");
				return;
			}
			try {  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
          }
        catch(ClassNotFoundException f){}
      try { con=DriverManager.getConnection("jdbc:odbc:tushuguan");
             sql=con.prepareStatement("SELECT * FROM guanliyuan where gid=? and gpass=?");
        
              sql.setString(1,name); 
              sql.setString(2,password);
              rs=sql.executeQuery();  
      	      if(rs.next()){
      	      	mainFrame.setEnable();
      	      	JOptionPane.showMessageDialog(this,"登陆成功!","提示话框",JOptionPane.INFORMATION_MESSAGE);
      	      	this.dispose();
      	      }
      	      else{
      	      	UserTextField.setText("");
    				PasswordTextField.setText("");
    				JOptionPane.showMessageDialog(this,"你输入帐号错误!","警告对话框",JOptionPane.WARNING_MESSAGE);
      	      }
    }
      catch(SQLException e2) 
           {  System.out.println(e2);
          }
		
			
		}
	}
	
}

⌨️ 快捷键说明

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