Use Java swing to achieve qq login interface sample sharing

  • 2020-04-01 03:10:57
  • OfStack

Using Java Swing to do a QQ login interface


import java.awt.Container;
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.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;


public class GUIQQ extends JFrame {
    //The user name
    private JTextField username;
    //password
    private JPasswordField password;
    //A small container
    private JLabel jl1;
    private JLabel jl2;
    private JLabel jl3;
    private JLabel jl4;

    //Small button
    private JButton bu1;
    private JButton bu2;
    private JButton bu3;

    //Check box
    private JCheckBox jc1;
    private JCheckBox jc2;

    //List box
    private JComboBox jcb;

    
    public GUIQQ() {
        //Set the window title
        this.setTitle("QQ2012 The final version ");
        //Form component initialization
        init();
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //Set the layout to absolute positioning
        this.setLayout(null);

        this.setBounds(0, 0, 355, 265);
        //Sets the title icon for the form
        Image image = new ImageIcon("e:/a.gif").getImage();
        this.setIconImage(image);

        //The form size cannot be changed
        this.setResizable(false);

        //centered
        this.setLocationRelativeTo(null);

        //The form is visible
        this.setVisible(true);
    }

    
    public void init() {
        //Create a container
        Container con = this.getContentPane();
        jl1 = new JLabel();
        //Set the background image
        Image image1 = new ImageIcon("e:/background.jpg").getImage();
        jl1.setIcon(new ImageIcon(image1));
        jl1.setBounds(0, 0, 355, 265);

        //QQ login avatar setting
        jl2 = new JLabel();
        Image image2 = new ImageIcon("e:/a.gif").getImage();
        jl2.setIcon(new ImageIcon(image2));
        jl2.setBounds(40, 95, 50, 60);

        //User number login input box
        username = new JTextField();
        username.setBounds(100, 100, 150, 20);
        //User number login input box Next to the text 
        jl3 = new JLabel(" Registered account ");
        jl3.setBounds(260, 100, 70, 20);

        //password Input box 
        password = new JPasswordField();
        password.setBounds(100, 130, 150, 20);
        //password The text next to the input box 
        jl4 = new JLabel(" Retrieve password ");
        jl4.setBounds(260, 130, 70, 20);

        //Enter the text at the bottom of the field
        jc1 = new JCheckBox(" Remember the password ");
        jc1.setBounds(105, 155, 80, 15);
        jc2 = new JCheckBox(" Automatic login ");
        jc2.setBounds(185, 155, 80, 15);
        //User login status selection
        jcb = new JComboBox();
        jcb.addItem(" online ");
        jcb.addItem(" stealth ");
        jcb.addItem(" leave ");
        jcb.setBounds(40, 150, 55, 20);

        //Button to set
        bu1 = new JButton(" The login ");
        bu1.setBounds(280, 200, 65, 20);
        //Add an event to the button
        bu1.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                String str=e.getActionCommand();
                if(" The login ".equals(str)){
                    String getName =username.getText();
//                  String getPwd =password.getText();
                     JOptionPane.showConfirmDialog(null, " The user name you entered is "+getName);
                }

            }
        });
        bu2 = new JButton(" More account ");
        bu2.setBounds(5, 200, 75, 20);
        bu3 = new JButton(" Set up the ");
        bu3.setBounds(100, 200, 65, 20);

        //All components are loaded in containers
        jl1.add(jl2);
        jl1.add(jl3);
        jl1.add(jl4);
        jl1.add(jc1);
        jl1.add(jc2);
        jl1.add(jcb);
        jl1.add(bu1);
        jl1.add(bu2);
        jl1.add(bu3);
        con.add(jl1);
        con.add(username);
        con.add(password);
    }
    public static void main(String[] args) {
        //Instantiate object
        GUIQQ qq = new GUIQQ();
    }
}


Related articles: