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

📄 login.java

📁 基于目前许多中小型公司, 机关,中小学校,大学院系等都有自己的图书库, 供内部人员借阅。传统的手工登记办法
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package libsystem;/** *  * @author admin */import java.awt.*;import java.awt.event.*;import java.util.logging.Level;import java.util.logging.Logger;import javax.swing.*;import java.sql.*;/** * 登录窗口 * @author admin */public class Login extends JFrame{	private JPanel panel;	private JLabel label0 = new JLabel();	private JLabel accountlabel = new JLabel();	private JLabel passwordlabel = new JLabel();        private Connection conn;        private Statement stmt;        private ResultSet rs;	private JTextField accountfield = new JTextField();	private JPasswordField passwordfield = new JPasswordField();	private JButton enterbut = new JButton();	public Login()	{               InitComponent();            super.setVisible(true);        }                private void InitComponent(){ //初始化组件	    panel = new JPanel();	    panel.setLayout(null);	    this.setTitle("图书馆管理系统 V1.0");	    this.setBounds(300,200,400,300);	    panel.setBackground(Color.black);		label0.setText("登录信息");		label0.setBounds(new Rectangle(155, 25, 200, 36));		label0.setFont(new Font("Dialog", 1, 20));		label0.setForeground(Color.white);                		accountlabel.setText("账号:");		accountlabel.setBounds(new Rectangle(123, 85, 49, 16));		accountlabel.setForeground(Color.white);		passwordlabel.setText("密码:");		passwordlabel.setBounds(new Rectangle(123, 122, 49, 16));		passwordlabel.setForeground(Color.white);		accountfield.setText("admin");		accountfield.setBounds(new Rectangle(192, 85, 70, 18));		passwordfield.setEchoChar('*');//返回要用于回显的字符。默认值为 '*'		passwordfield.setText("123456");		passwordfield.setBounds(new Rectangle(192, 122, 70, 18));		enterbut.setText("进入系统");		enterbut.setVisible(true);		enterbut.setBounds(new Rectangle(150, 180, 101, 22));		enterbut.setForeground(Color.white);		enterbut.setBackground(Color.black);                enterbut.addActionListener(new ActionListener (){                    public void actionPerformed(ActionEvent e)                        {			String user = accountfield.getText().trim();			String password = passwordfield.getText().trim();      			/****判断用户输入的信息****/      			if(user.equals("")|| password.equals(""))      				JOptionPane.showMessageDialog(null, "账号或密码不能为空", "警告",                                      JOptionPane.WARNING_MESSAGE);      			else {                    try {                        /*从数据库中查询用户名(admin)和密码(admin)*/                        stmt = ConnDataBase.getConnection().createStatement();                        rs = stmt.executeQuery("select * from Account where ID='" + user + "' AND password='" + password + "'");                        /*如果信息正确则进行以下操作*/                        if (rs.next()) {                            JOptionPane.showMessageDialog(null, "登陆成功");                            new Console().addWindowListener(new WindowAdapter() {                                public void windowClosing(WindowEvent e) {                                    try {                                        ConnDataBase.getConnection().close();                                        System.exit(1);//退出程序用,dipose()只能关闭释放窗口,线程没结束                                    } catch (SQLException ex) {                                        System.out.println("无法断开连接");                                        ex.printStackTrace();                                    }                                }                            });                            dispose();                        } else {                            JOptionPane.showMessageDialog(null, "账号或密码输入错误", "警告", JOptionPane.WARNING_MESSAGE);                        }                        accountfield.setText("");                        passwordfield.setText("");                    } catch (SQLException ex) {                        Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);                    }                    }		}	});		panel.add(label0);		panel.add(accountlabel);		panel.add(passwordlabel);		panel.add(accountfield);		panel.add(passwordfield);		panel.add(enterbut);                super.add(panel);        }//Init                     }

⌨️ 快捷键说明

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