java swing login interface + jump interface

 
  
package Example;
/**
 * @author:
* @function: User login interface implementation, jump to monitoring data interface
 */
import java.awt.Font;

import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class helloLabel extends JFrame{
	private static int count=0;
	private static JButton bt1;//Login button
	private static JButton bt2;//Forgot password button
	private static JLabel jl_1;//Login page
	private static JFrame jf_1;//Login frame
    private static JTextField jtext1;//Username
    private static JPasswordField jtext2;//密码
    private static JLabel jl_admin;
    private static JLabel jl_password;
    public helloLabel (){//Initialize the login interface
    	Font font =new Font("Black Body", Font.PLAIN, 20);//Set the font
	    jf_1=new JFrame("Login interface");
		jf_1.setSize (450, 400);
		//Add a background image to the login interface
		ImageIcon bgim = new ImageIcon(helloLabel.class.getResource("baozou.PNG")) ;//背景图案
		bgim.setImage(bgim.getImage().
				                     getScaledInstance(bgim.getIconWidth(),
												       bgim.getIconHeight(),
												       Image.SCALE_DEFAULT));  
		jl_1=new JLabel();
		jl_1.setIcon(bgim);
		
		jl_admin=new JLabel("Username");
		jl_admin.setBounds(20, 50, 60, 50);
		jl_admin.setFont(font);
		
		jl_password=new JLabel("password");
		jl_password.setBounds(20, 120, 60, 50);
		jl_password.setFont(font);
		
		bt1=new JButton("Login"); //Change to loginButton
		bt1.setBounds(90, 250, 100, 50);
		bt1.setFont(font);

		bt2=new JButton("退出");
		bt2.setBounds(250, 250, 100, 50);
		bt2.setFont(font);

		//add textbox
		jtext1=new JTextField("root");
		jtext1.setBounds(150, 50, 250, 50);
		jtext1.setFont(font);
		
		jtext2=new JPasswordField("123456");//Password input box
		jtext2.setBounds(150, 120, 250, 50);
		jtext2.setFont(font);
		
		jl_1.add(jtext1);
		jl_1.add(jtext2);
		
		jl_1.add(jl_admin);
		jl_1.add(jl_password);
		jl_1.add(bt1);
		jl_1.add(bt2);
		
		jf_1.add(jl_1);
		jf_1.setVisible(true);
		jf_1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jf_1.setLocation(300,400);
	}
	public static void main(String[] args) {
		//Initialize the login interface
		 
		helloLabel hl = new helloLabel ();
		/**
		 * handle click event
		 * 1. The login button click event to judge whether the account password is correct, if it is correct, the monitoring information interface will pop up
		 * Otherwise, no response (temporarily no response)
		 * : After that, you can add a logLabel to the login interface to prompt the user whether the user password is correct
		 * 2. Exit button, exit the program directly
		 */
		//login click event
		ActionListener bt1_ls=new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				String admin=jtext1.getText();
				char[] password=jtext2.getPassword();
				String str=String.valueOf(password); //Convert char array to string type
				
				if(admin.equals("root")&&str.equals("123456"))
				{
					   
					System.out.println(admin);
					System.out.println(str);
					mainLayout ml=new mainLayout();//Interface for jumping
					hl.jf_1.dispose();//Destroy the current interface
				}
				else {
					count++;
					System.out.println("error");
					if(count==3){
						hl.jf_1.dispose();
					}
				}
			}
		};
		bt1.addActionListener (bt1_ls);
		// handle the exit event
		ActionListener bt2_ls=new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				System.exit(0);//Terminate the current program
			}
		};
        bt2.addActionListener (bt2_ls);		
     }
}

Recently, I am working on a junk project. It has been a year since I got started with java and gave up. . . It’s very bad to write java code again. I need to write a swing interface, mainly to realize serial communication. I may follow up the project and update the blog in two or three days. If you have something to do, you can come and see it. Post the code first.
I wrote a bunch of junk code on the login interface tonight
The above is the login interface: helloJlabel.java
The jump interface is the interface for displaying serial communication data. It will be posted tomorrow. Don't look at this interface for the time being, it is useless to read it. . . .
The code is badly written, I hope all the gods will lightly spray it. . . .
package Example;
/*
 * @author :
 * @Function: Main monitoring interface, display temperature, humidity, light intensity,
 * @Code logic is mainly for processing serial communication code
 */

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class mainLayout extends JFrame{
   private static JFrame jf;
   private static JLabel jl;
   private static JButton bt_open;
   private static JButton bt_close;
   private static JButton bt_sysInfo;
   private static JButton bt_back;

   public mainLayout(){
	   jf=new JFrame("i am the new JFrame");
	   jf.setVisible(true);
	   jf.setLocation(10, 10);
	   cf. setBounds (10, 10, 100, 100);
	   jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   }

   public static void main(String[] args) {
        mainLayout ml=new mainLayout();
     }
}


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325278430&siteId=291194637