Write a simple user login interface

Source: Internet
Author: User

1, if the user name and password do not fill out//pop-up message dialog prompts to enter the user name and password//2, if the user name and password is filled in//(1), if the user name and password is filled in the admin pop-up message dialog box, prompt login Success//(2), If the user name and password are filled in two are not admin pop-up dialog box prompt login or password errorimport Java.awt.gridlayout;import java.awt.event.actionevent;import java.awt.event.ActionListener;import javax.swing.jbutton;import javax.swing.jframe;import javax.swing.jlabel;import Javax.swing.JOptionPane; Import Javax.swing.jpanel;import Javax.swing.jpasswordfield;import Javax.swing.jtextfield;import Javax.swing.event.AncestorListener;Public classUsertestextendsJFrameImplementsActionListener () {//Add tagsJlable ul = new jlable (user name); Jlable PL = new jlable (password);//text box, lengthjtextfiled ut = new JTextField (13);//Password box, length ofJtexedfield pt = new JTextField (13);//ButtonJButton login = new JButton ("login"); JButton Cancel = new JButton ("Cancel");//PanelJPanel P1 = new JPanel (); Jpanel P2 = new Jpanel (); JPanel p3 = new JPanel ();//Construction methodPublic Usertest () {this.settitle ("User login Test");//Add the control to the panelP1.add (UL);p 1.add (UT);p 2.add (PL);p 2.add (UT);p 3.add (login);p 3.add (cancel);//Set form sizeThis.setsize (200,200);//Set form layout mode Grid layout 2 rows 3 columnsThis.setlayout (new GridLayout (2,3));//Put the Panel on the formThis.add (p1); This.add (p2); This.add (p3);//form visibleThis.setvisible (TRUE);
//form can be closedThis.setdefaultcloseoperation (Jframe.exit_on_close);@Override //Override listener methodpublic void actionperformed (ActionEvent e) {if (e.getsource () = = login) {//Monitor Login buttonif (Ut.gettext (). Equals ("admin") &&pt.gettext (). Equals ("admin")) {//Do not overwrite formJoptionpane.showmessagedialog (NULL, "Login succeeded");} else if (Ut.gettext (). Equals ("") | | Pt.gettext (). Equals ("")) {Joptionpane.showmessagedialog (null, "User name or password cannot be null");} Else{joptionpane.showmessagedialog (NULL, "User name or password error");}}} Public Staticvoid Main (string[] args) {new usertest ();//Invoke parameterless construction method test program}



Write a simple user login interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.