A QQ login interface made with Java Swing
Copy the code code as follows:
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;
/**
* Imitation QQ login interface
*
* @author jiang
*/
public class GUIQQ extends JFrame {
// username
private JTextField username;
// password
private JPasswordField password;
// small container
private JLabel jl1;
private JLabel jl2;
private JLabel jl3;
private JLabel jl4;
// small button
privateJButtonbu1;
privateJButtonbu2;
privateJButtonbu3;
// checkbox
private JCheckBox jc1;
private JCheckBox jc2;
// list box
private JComboBox jcb;
/*
*Construction method
*/
public GUIQQ() {
//Set window title
this.setTitle("QQ2012 official version");
// form component initialization
init();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Set the layout mode to absolute positioning
this.setLayout(null);
this.setBounds(0, 0, 355, 265);
//Set the title icon of the form
Image image = new ImageIcon("e:/a.gif").getImage();
this.setIconImage(image);
//The size of the form cannot be changed
this.setResizable(false);
// Center display
this.setLocationRelativeTo(null);
//The form is visible
this.setVisible(true);
}
/*
* Initialization method
*/
public void init() {
//Create a container
Container con = this.getContentPane();
jl1 = new JLabel();
//Set 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);
//The text next to the user number login input box
jl3 = new JLabel("Register Account");
jl3.setBounds(260, 100, 70, 20);
//Password input box
password = new JPasswordField();
password.setBounds(100, 130, 150, 20);
//The text next to the password input box
jl4 = new JLabel("Retrieve password");
jl4.setBounds(260, 130, 70, 20);
//Text below the input box
jc1 = new JCheckBox("Remember 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("Invisible");
jcb.addItem("Leave");
jcb.setBounds(40, 150, 55, 20);
// Button settings
bu1 = new JButton("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("Login".equals(str)){
String getName =username.getText();
// String getPwd =password.getText();
JOptionPane.showConfirmDialog(null, "The user name you entered is "+getName);
}
}
});
bu2 = new JButton("Multiple Accounts");
bu2.setBounds(5, 200, 75, 20);
bu3 = new JButton("setting");
bu3.setBounds(100, 200, 65, 20);
// All components are loaded into 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();
}
}