Import Java.awt.BorderLayout;
Import 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;
/**
* @author Greatwqs
* @date October 19, 2009
*/
public class Loginframe extends JFrame {
Public Loginframe () {
Super ("Management system Login");
This.setbounds (280, 280, 300, 200);
SetLayout (New BorderLayout ());
Set the width and height of the login interface
JPanel P1 = new JPanel ();
P1.setlayout (New GridLayout (2, 2));
P1.add (Userl);
P1.add (user);
P1.add (PASSWORDL);
P1.add (password);
P1.setsize (150, 100);
JPanel P2 = new JPanel ();
P2.add (OK);
P2.add (cancel);
Add ("North", p1);
Add ("Center", p2);
Add ("South", cue);
So far, the landing interface is basically over! The following is to set the specific event listener for the button inside
Cancel.addactionlistener (new ActionListener () {
public void actionperformed (ActionEvent e) {
System.exit (0);
}
//Set the Cancel button when landing, press this button to exit all Programs
Ok.addactionlistener (new ActionListener () {
public void actionperformed (ActionEvent e) {
if ((User.gettext ()). Equals ("Team")
&& string.valueof ((Password.getpassword ()). Equals (
"Team") {
result = true;
Hidfun ();
Joptionpane.showmessagedialog (null, "Hello: You landed successfully, enter the system!");
} else {
Cue.settext ("The password you entered is wrong!");
Joptionpane.showmessagedialog (null, "Hello: you entered the wrong password, please re-enter!");
}
}
}
//Set the OK key to the event listener, and verify the username and password, password input error prompts "You entered the wrong password!"
}
public boolean islogin () {
return result;
}
/**
* Set this interface to hide.
*
*/
private void Hidfun () {
This.setvisible (FALSE);
}
Private JLabel Userl = new JLabel ("username");
Private JLabel passwordl = new JLabel ("password");
Private JLabel cue = new JLabel ();
Private JTextField user = new JTextField ("team");
Private JPasswordField Password = new JPasswordField ();
Private JButton OK = new JButton ("OK");
Private JButton Cancel = new JButton ("Exit");
Private Boolean result = false;
/**
* Main function .....
*
* @param WQS
*/
public static void Main (string[] wqs) {
Loginframe oop = new Loginframe ();
Oop.setvisible (TRUE);
Oop.setdefaultcloseoperation (Jframe.exit_on_close);
}
}
Import javax.swing.*;
Import java.awt.*;
Import java.awt.event.ActionEvent;
Import Java.awt.event.ActionListener;
public class Nulllayoutdemo extends JFrame implements ActionListener {
Private JLabel Lbuser = new JLabel ();
Private JLabel info = new JLabel ();
Private JLabel Lbpassword = new JLabel ();
Private JButton Btnlog = new JButton ()//* There's something wrong with that line.
Private Container Container = Getcontentpane ();
Private JTextField jtextfield_1 = new JTextField (10);
Private JPasswordField jtextfield_2 = new JPasswordField (10);
Public Nulllayoutdemo () {
Super ("Lander");
This.setsize (350, 200);
This.setdefaultcloseoperation (Jframe.exit_on_close);
}
public static void Main (string[] args) {
Nulllayoutdemo frame = new Nulllayoutdemo ();
Frame.setlayout ();
Frame.setvisible (TRUE);
}
public void setlayout () {
Container.setlayout (NULL);
Lbuser.settext ("User name");
Container.add (Lbuser);
Container.add (jtextfield_1); Add text box to enter user name
Jtextfield_1.setbounds (80, 26, 120, 26);//Set the text box position of the user name
Lbuser.setbounds (16, 26, 42, 16);
Lbpassword.settext ("password");
Container.add (Lbpassword);
Lbpassword.setbounds (16, 56, 40, 16);
Btnlog.settext ("Landing");
Jtextfield_2.setechochar (' $ ');
Container.add (jtextfield_2);//Set text box position for password
Jtextfield_2.setbounds (80, 56, 120, 26);//Increase the text box for the password entered
Container.add (Btnlog);
Btnlog.addactionlistener (this);
Btnlog.setbounds (125, 101, 73, 25);
Info.setbounds (0, 130, 300, 35); Set up labels for information
Info.settext ("username is: name password is: password");
Container.add (info);
/*
* public void Ceshi () {if ()}
*/
}
public void actionperformed (ActionEvent e) {
String name = Jtextfield_1.gettext (); Get information about the user name text box
String password = jtextfield_2.gettext ();//Get Password text box information
To determine whether a condition is met
if ("Name". Equals (name) && "password". Equals (password)) {
Joptionpane.showmessagedialog (This, "congratulations.") Input correctly "," through ",
Joptionpane.information_message, NULL);
} else {
Joptionpane.showmessagedialog (This, "Your input error", "Error",
Joptionpane.information_message, NULL);
}
}
}