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

📄 booklogin.java

📁 Java Swing写的图书馆管理系统
💻 JAVA
字号:
package library.iframe;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import library.Library;
import library.DBConnectOperation.Dbo;
import library.model.Operator;
import library.util.CreateIcon;

public class BookLogin extends JFrame {
	private JTextField username;
	private JPasswordField password;
	private JButton login;
	private JButton reset;
	private static Operator operator;
	
	public BookLogin(){
		super();
        setResizable(false);
        BorderLayout borderLayout=new BorderLayout();
        setBounds(100, 100, 285, 194);
        setTitle("图书馆管理系统登陆");
        getContentPane().setLayout(borderLayout);
        JPanel panel=new JPanel();
        panel.setLayout(new BorderLayout());
        getContentPane().add(panel);
        
        //设置框架中部的用户名和密码框开始
        JPanel panelCenter=new JPanel();
        GridLayout gridLayout=new GridLayout(0,2);
        gridLayout.setHgap(3);	//设置该布局管理器中组建的水平间距
        gridLayout.setVgap(20);
        panelCenter.setLayout(gridLayout);
        panel.add(panelCenter);
        
        JLabel usernamelabel=new JLabel();
        usernamelabel.setHorizontalAlignment(SwingConstants.RIGHT);
        panelCenter.add(usernamelabel);
        usernamelabel.setText("用户名:");
        username=new JTextField(20);
        panelCenter.add(username);
        
        JLabel passwordlabel=new JLabel();
        passwordlabel.setHorizontalAlignment(SwingConstants.RIGHT);
        passwordlabel.setText("密码:");
        panelCenter.add(passwordlabel);
        
        password=new JPasswordField(20);
        panelCenter.add(password);
        //设置框架中部的用户名和密码框结束
        
        //创建底部按钮面板开始
        JPanel panelBottom=new JPanel();	
        panel.add(panelBottom,BorderLayout.SOUTH);
        login=new JButton();
        login.addActionListener(new BookLoginAction());
        login.setText("登陆");
        panelBottom.add(login);
        reset=new JButton();
        reset.addActionListener(new BookResetAction());
        reset.setText("重置");
        panelBottom.add(reset);
        //创建底部按钮面板结束
        //设置顶部图片开始
        JLabel topPicLabel=new JLabel();
        topPicLabel.setIcon(CreateIcon.add("login.jpg"));
        topPicLabel.setPreferredSize(new Dimension(260, 60));
        panel.add(topPicLabel,BorderLayout.NORTH);

        //设置顶部图片结束
        setVisible(true);
        setResizable(false);
	}

	class BookLoginAction implements ActionListener{
		public void actionPerformed(ActionEvent e){
			operator=Dbo.check(username.getText(),password.getText());
			if(operator.getName()!=null){
				try{
					Library frame=new Library();
					BookLogin.this.setVisible(false);
				}catch(Exception se){
					se.printStackTrace();
				}
			}
			else{
				JOptionPane.showMessageDialog(BookLogin.this,"您输入的用户名或密码错误!");
				username.setText("");
				password.setText("");
			}
		}
	}
	
	class BookResetAction implements ActionListener{
		public void actionPerformed(ActionEvent e){
			username.setText("");
			password.setText("");
		}
	}
	public static Operator getOperator(){
		return operator;
	}
}

⌨️ 快捷键说明

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