This article shares the specific code for Java to implement a simple QQ login interface for your reference. The specific content is as follows
Java is not a strong point in the graphical interface, but it is not impossible to do it. Its open source is very nice!
The implementation code is as follows (if you want to implement a perfect interface, you may need more coding support):
package com.ts.x.swing; import java.awt.Color; import java.awt.Container; import java.awt.Cursor; 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.JCheckBox; import javax.swing.JComboBox; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPasswordField; import javax.swing.JRootPane; import javax.swing.JTextField; public class QQ extends JFrame{ private static final long serialVersionUID = -6788045638380819221L; //Username private JTextField ulName; //Password private JPasswordField ulPasswd; //Small container private JLabel j1; private JLabel j2; private JLabel j3; private JLabel j4; //Small button private JButton b1; private JButton b2; private JButton b3; //Checkbox private JCheckBox c1; private JCheckBox c2; //List box private JComboBox<String> cb1; /** * Initialize QQ login page* */ public QQ(){ //Set the login window title this.setTitle("QQ login"); //Remove the window decoration (border) // this.setUndecorated(true); //Use the specified window decorative style this.getRootPane().setWindowDecorationStyle(JRootPane.NONE); //Initialize the form component init(); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set the layout to absolute positioning this.setLayout(null); this.setBounds(0, 0, 355, 265); //Set the form icon Image img0 = new ImageIcon("D:/logo.png").getImage(); this.setIconImage(img0); //The size of the form cannot be changed this.setResizable(false); //The center displays this.setLocationRelativeTo(null); //The form displays this.setVisible(true); } /** * Form component initialization* */ public void init(){ //Create a container, the image size and the third and fourth parameters of setBounds must be basically the same (you need to calculate and crop it yourself) Container container = this.getContentPane(); j1 = new JLabel(); //Set the background color Image img1 = new ImageIcon("D:/bgimg.png").getImage(); j1.setIcon(new ImageIcon(img1)); j1.setBounds(0, 0, 355, 265); //qq avatar setting j2 = new JLabel(); Image img2 = new ImageIcon("D:/hdimg.png").getImage(); j2.setIcon(new ImageIcon(img2)); j2.setBounds(40, 95, 50, 53); //User name input box ulName = new JTextField(); ulName.setBounds(100, 100, 150, 20); //Register account j3 = new JLabel("Register account"); j3.setBounds(260, 100, 70, 20); //Password input box ulPasswd = new JPasswordField(); ulPasswd.setBounds(100, 130, 150, 20); //Retrieve password j4= new JLabel("Retrieve password"); j4.setBounds(260, 130, 70, 20); //Remember password c1 = new JCheckBox("Remember password"); c1.setBounds(105, 155, 80, 15); //Automatic login c2 = new JCheckBox("Automatic login"); c2.setBounds(185, 155, 80, 15); //User login status selection cb1 = new JComboBox<String>(); cb1.addItem("online"); cb1.addItem("invisible"); cb1.addItem("leave"); cb1.setBounds(40, 150, 55, 20); //Login button b1 = new JButton("Login"); //Set font and color and hand pointer b1.setFont(new Font("宋体", Font.PLAIN, 12)); b1.setForeground(Color.RED); b1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); b1.setBounds(280, 200, 65, 20); //Add b1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if("Login".equals(cmd)){ String username = ulName.getText(); String userpassword = ulPasswd.getText(); if(username.equals("tskk") && userpassword.equals("123456")){ JOptionPane.showConfirmDialog(null, "Login successfully"); }else{ JOptionPane.showConfirmDialog(null, "Login failed"); } } } } }); //Multiple account b2 = new JButton("Multiple account"); b2.setBounds(5, 200, 75, 20); //Setb3 = new JButton("Set"); b3.setBounds(100, 200, 65, 20); //All components are loaded with container j1.add(j2); j1.add(j3); j1.add(j4); j1.add(c1); j1.add(c2); j1.add(cb1); j1.add(b1); j1.add(b2); j1.add(b3); container.add(j1); container.add(ulName); container.add(ulPasswd); } public static void main(String[] args) { new QQ(); } }The running result interface is:
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.