java--User Login Interface

Source: Internet
Author: User

1  Packagecom.swing;2 /*3 * User name Password login interface, add to determine whether the user name and password is correct4  * */5 Importjava.awt.*;6 Importjavax.swing.*;7 Importjava.awt.event.*;8  Public classDengluchuangkouextendsJFrame {9 Ten      Public Static voidMain (string[] args) { One         //TODO auto-generated Method Stub A         NewDengluchuangkou (); -     } -      PublicDengluchuangkou () { theJFrame jf=NewJFrame (); -Container container=Jf.getcontentpane (); -Jf.setbounds (300,200,300,180); -Container.setlayout (NULL); +          -JLabel jl1=NewJLabel ("User name"); +Jl1.setbounds (10,10, 50, 20); A         //JTextArea name=new JTextArea ();//textarea can be more than one line, you can add scroll bar atJTextField name=NewJTextField ();//TextField only one line to write -Name.setbounds (80,10,150,20); -JLabel jl2=NewJLabel ("Password"); -Jl2.setbounds (10,50,50,20); -JPasswordField password=NewJPasswordField (); -Password.setbounds (80,50,150,20); in Container.add (JL1); - Container.add (name); to Container.add (JL2); + container.add (password); -          theJButton jb1=NewJButton ("OK"); *Jb1.setbounds (40,90,80,30); $JButton jb2=NewJButton ("Reset");Panax NotoginsengJb2.setbounds (170,90,80,30); - Container.add (JB1); the Container.add (JB2); +          AJf.setvisible (true); the jf.setdefaultcloseoperation (dispose_on_close); +          -         //Setting up monitoring $Jb1.addactionlistener (NewActionListener () { $              Public voidactionperformed (ActionEvent e) { -                 if(Name.gettext (). Trim (). Equals ("admin") &&password.gettext (). Trim (). Equals ("admin")){ -Joptionpane.showmessagedialog (NULL, "Login Successful"); the                 } -                 if(Name.gettext (). Trim (). Length () ==0| | Password.gettext (). Trim (). Length () ==0){WuyiJoptionpane.showmessagedialog (NULL, "The user name or password cannot be empty!" "); the}Else{ -Joptionpane.showmessagedialog (NULL, "The user name or password is wrong! "); Wu                 } -                  About             } $         }); -          -Jb2.addactionlistener (NewActionListener () { -              Public voidactionperformed (ActionEvent e) { AName.settext (""); +Password.settext (""); the             } -         }); $          the     } the}

java--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.