Package COM.LZW;
Import java.awt.*;
Import java.awt.event.*;
Import javax.swing.*;
public class UseCase3 extends jframe{
/**
*
*/
Private static final long serialversionuid = 1L;
Public UseCase3 () {
SetVisible (TRUE);
Setdefaultcloseoperation (Windowconstants.dispose_on_close);
Settitle ("login form");
SetBounds (300, 200, 300, 150);
Container Cp=getcontentpane ();
Cp.setlayout (NULL);
JLabel jl=new JLabel ("User name:");
Jl.setbounds (10, 10, 200, 18);
Final JTextField name=new JTextField ();
Name.setbounds (80, 10, 150, 18);
JLabel jl2=new JLabel ("Password:");
Jl2.setbounds (10, 50, 200, 18);
Final JPasswordField password=new JPasswordField ();
Password.setbounds (80, 50, 150, 18);
Cp.add (JL);
Cp.add (name);
Cp.add (JL2);
Cp.add (password);
JButton jb=new JButton ("OK");
Jb.addactionlistener (new ActionListener () {
public void actionperformed (ActionEvent arg0) {
if (Name.gettext (). Trim (). Length () ==0| | New String (Password.getpassword ()). Trim (). Length () ==0) {
Joptionpane.showmessagedialog (NULL, "User name password is not allowed to be empty");
Return
}
if (Name.gettext (). Trim (). Equals ("my") &&new String (Password.getpassword ()). Trim (). Equals ("Love")) {
Joptionpane.showmessagedialog (NULL, "Login succeeded");
}
else{
Joptionpane.showmessagedialog (NULL, "User name or password error");
}
}
});
Jb.setbounds (80, 80, 60, 18);
Cp.add (JB);
Final JButton button = new JButton ();
Button.settext ("reset");
Button.addactionlistener (new ActionListener () {
public void actionperformed (ActionEvent arg0) {
TODO automatically generate method stubs
Name.settext ("");
Password.settext ("");
}
});
Button.setbounds (150, 80, 60, 18);
Getcontentpane (). Add (button);
}
public static void Main (string[] args) {
New UseCase3 ();
}
}
Java_swing Programming _ try to develop a login form, including user name, password and submit button and reset button, when the user entered the user name my, password love, pop up the Login Success prompt dialog box.