Java realization QQ Login interface
QQ Login interface is also a kind of interface , When implementing the interface, we need some interface development packages , as :
package – Code classification in a project
System library :
java.awt – Early interface development packages Keep using element classes
javax.swing – After the interface development package is upgraded – Visualization component
Then we need to have the following steps when setting the interface

* Create a form object
* set a property
* Set the layout manager for component placement
* Add components public class LoginUI { public static void main (String[] args) {
LoginUI loginui=new LoginUI(); loginui.initUI(); } // Create a form class object public void
initUI() { JFrame jf = new JFrame(); // Set form properties jf.setTitle("QQ Sign in "); jf.setSize(
500,500);// wide high Company : pixel jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//
Exit the program when closing jf.setLocationRelativeTo(null);// Center display // Set up layout manager ( Streaming layout ) FlowLayout fl =
new FlowLayout(); jf.setLayout(fl); // Add components // picture - label ImageIcon img = new
ImageIcon("C:\\Users\\86189\\Pictures\\Saved Pictures\\QQ music 1.jpg"); JLabel
imgjla= new JLabel(img); // written words label JLabel namejla = new JLabel(" account number :"); JLabel
pwdjla= new JLabel(" password :"); // Input box JTextField nameField = new JTextField();
JPasswordField pwdField= new JPasswordField(); // Button JButton btn = new JButton(
" Sign in "); JButton btn1 = new JButton(" register "); // Set the properties of the component object btn.setBackground(Color.
white); // size Dimension dim = new Dimension(400,30); nameField.setPreferredSize(
dim); pwdField.setPreferredSize(dim); // Load on form jf.add(imgjla); jf.add(namejla);
jf.add(nameField); jf.add(pwdjla); jf.add(pwdField); jf.add(btn); jf.add(btn1);
jf.setVisible(true);// visualization Show form on screen It needs to be placed after all components are loaded } }
According to the code in the figure, our simple QQ The login interface is completed , After that, we can consider filling in the information in the input box of ah account password , Then verify , At this point, we need to use a listener , Interface
Interface keyword :erface - - Abstraction of methods
1, A method with a method body cannot be created in an interface 2, Cannot create variable in interface -- Constants can be declared 3, Implementation interface Create a class to implement the interface format : public class Class name
implements Interface name { } All abstract methods in the interface must be implemented in the class The object of this class can also be used as a parameter of the interface type And the method after implementation is called
After understanding the interface , We just need to btn Just add a listener at the button
// Create an object of a class that implements the listener interface LoginUIListener loginlistener = new LoginUIListener(); //
Button add listener btn.addActionListener(loginlistener); btn1.addActionListener(
loginlistener); // The input box object Incoming listener loginlistener.nameField = nameField;
loginlistener.pwdField = pwdField;
To join the listener, we need to create another class to implement the interface we need
public class LoginUIListener implements ActionListener{ JTextField nameField=
null; JPasswordField pwdField=null; // Implement abstract methods in interfaces public void actionPerformed(
ActionEvent e) { // Gets the word on the button String btnstr = e.getActionCommand(); if(btnstr.
equals(" Sign in ")) { System.out.println("nameF="+nameField); String namestr =
nameField.getText(); String pwdstr = pwdField.getText(); if(namestr.equals(
"admin") && pwdstr.equals("123")) { System.out.println(" Login successful !!"); }else { System
.out.println(" Please try again !!"); } }else if(btnstr.equals(" register ")) { } System.out.println(
btnstr+ " = The button was clicked "); } }
Here we need to pay attention to one thing , When calling the interface , The semicolon in the interface function is used in the class {} replace
Up to now, one QQ The login interface is completed .

©2019-2020 Toolsou All rights reserved,
JavaScript note ( five )---- Branch statement Linux【shell】 shell programming Account password registration login forgotten password test case ( Very detailed )abaqus Value of mass scaling factor _ABAQUS Mass scaling for vue in input Box can only enter numbers RISC-V_GD32VF103-TIMER0 timer interrupt Java Student information management system console version 【 Hyper detail 】Java Realization of student information management system pandas Multiply two columns in html+css curriculum vitae / Web interface