Front has been looking at the video learning, follow the teacher also wrote a small code, but just write code, write code without soul, a few days ago suddenly feel, do a little thing, may learn faster, and then spent a week time, wrote the books management system management system, today to do a summary, first of all, think to learn while doing is a very good method, Although there are a lot of problems, but when you really spend time to solve the problem one by one, debugging a bug, you can feel the soul of the code, when a bug is solved, the heart will have a sense of achievement, so slowly progress, feeling good. In addition, I heard an upperclassman’s speech before that the way to learn is not to just look and do. As a student of science and engineering, you must learn and do while learning. Now it is not the time to ask teachers and classmates for questions. Eighty percent of the problems we are now encountering have been met and solved by senior students and senior students. It is really impossible for us to figure it out. If we cannot find it out on Baidu, we will ask senior students and teachers. Don’t feel that you can’t do something when you get it in your hand. If you haven’t done it, how can you know that you can’t do it? Maybe you can do it as soon as you do it. Experienced a small stage of learning, to their knowledge and skills to do a summary, next, about the library management system: the current do this, can only be said to be a practice of small procedures, even on the front of learning graphical interface and file reading and writing a summary, well, first look at the effect:

I. Login page (enter the login page after running the program) All page functions are realized

 

If the login account is not registered, a message ~~~~ is displayed indicating that the account does not exist

If the login account has been registered but the login password is incorrect, ~~~~~~~~~~~~~ is displayed

Let’s look at the code implementation !!!!!!

package Library;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

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;

public class Login extends JFrame implements ActionListener{
	/ / button
	JButton btnLogin,btnRegister,btnCancel;
	// Create an intermediate container
	JPanel pnlSouth,pnlNorth,pnlCenter,pnlCenter1,pnlCenter2;
	/ / label
	JLabel lbl1,JLabelNum,JLabelPwd;
	// User name text box
	JTextField tfNum;
	// Password text box
	JPasswordField tfPwd;
	// Create window
	Login(String title){
		super(title);
		
		//north
		pnlNorth = new JPanel();
		lbl1 = new JLabel("Welcome to the Library Management system!");
		pnlNorth.add(lbl1);
		this.add(pnlNorth,BorderLayout.NORTH);
		
		//center
		pnlCenter=new JPanel();
		pnlCenter1=new JPanel();
		pnlCenter2=new JPanel();
		pnlCenter.setLayout(new BorderLayout());
		JLabelNum=new JLabel("Student Number:");
		tfNum=new JTextField(15);
		pnlCenter1.add(JLabelNum);
		pnlCenter1.add(tfNum);
		pnlCenter.add(pnlCenter1,BorderLayout.NORTH);
		JLabelPwd=new JLabel("Key code:");
		tfPwd=new JPasswordField(15);
		pnlCenter2.add(JLabelPwd);
		pnlCenter2.add(tfPwd);
		pnlCenter.add(pnlCenter2,BorderLayout.SOUTH);
		this.add(pnlCenter,BorderLayout.CENTER); 

		//south
		pnlSouth = new JPanel();
		
		// Generate a button
		btnLogin = new JButton("Login");
		btnLogin.addActionListener(this);

		btnRegister = new JButton("Registered");
		btnRegister.addActionListener(this);

		btnCancel = new JButton("Cancel");
		btnCancel.addActionListener(this);

		// Place the three buttons in an intermediate container
		pnlSouth.add(btnLogin);
		pnlSouth.add(btnRegister);
		pnlSouth.add(btnCancel);
		// Add the button to the graphical interface
		//this.add(btnLogin);
		//this.add(btnRegister);
		//this.add(btnCancel);
		this.add(pnlSouth,BorderLayout.SOUTH);

		this.setSize(400.180);
		GUIUtil.toCenter(this);// Center the window
		this.setVisible(true);/ / visualization
		this.setResizable(false);// Close the zoom window
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// Set error close operation
		
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==btnLogin){
			String num = tfNum.getText();
			String pwd = tfPwd.getText();
			FileOpe.getInfoByAccount(num);
			if(User.num==null){
				JOptionPane.showMessageDialog(this."The account you entered does not exist, please re-enter!");
				return;
			}
			if(! User.pwd.equals(pwd)){ JOptionPane.showMessageDialog(this."The password you entered is wrong, please re-enter!");
				return;
			}
			JOptionPane.showMessageDialog(this."Congratulations, login success!");
			this.dispose();
			
			/ * * * * * * * * * * * * * * * * * * * * * * * * * * set the password for the administrator account * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
			if(User.num.equals("20173821057")&&User.pwd.equals("123456")) {new AdminFunction();
				return;
			}else if(User.num.equals("2")&&User.pwd.equals("2")) {new AdminFunction();
				return;
			}
			new UserFunction();
			
		}else if(e.getSource()==btnRegister){
			dispose();// Close the login page and go to the registration page
			new Register("User Registration");
		}else {
            JOptionPane.showMessageDialog(this."Thank you for using this system, welcome to use it again next time!");
            System.exit(0); }}}Copy the code

Okok, the first stage, the user login page is finished, next, the user registration page ~~

Any questions in the article are welcome to harass yo, the blogger hopes to progress with you ~~~~~~