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