/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package 图形界面;
/**
*
* @author 肖硕
* qq: 277850117
* 创建时间: 2011-6-20 14:58:24
*/
import java.awt.event.*;
import javax.swing.*;
class LoginCheck {
private String name;
private String password;
public LoginCheck(String name, String password) {
this.name = name;
this.password = password;
}
public boolean validate() {
if ("肖硕".equals(name) && "love".equals(password)) {
return true;
} else {
return false;
}
}
}
class ActionHandleDemo {
private JFrame frame = new JFrame("肖硕");
private JButton submit = new JButton("提交");
private JButton reset = new JButton("重置");
private JLabel nameLab = new JLabel("用户名");
private JLabel passLab = new JLabel("密码");
private JTextField nameText = new JTextField();
private JPasswordField passText = new JPasswordField();
private JLabel infoLab = new JLabel("用户登录界面");
public ActionHandleDemo() {
frame.setLayout(null);
nameLab.setBounds(5, 5, 60, 20);
passLab.setBounds(5, 30, 60, 20);
infoLab.setBounds(5, 65, 220, 30);
nameText.setBounds(65, 5, 100, 20);
passText.setBounds(65, 30, 100, 20);
submit.setBounds(165, 5, 60, 20);
reset.setBounds(165, 30, 60, 20);
frame.add(nameLab);
frame.add(passLab);
frame.add(infoLab);
frame.add(nameText);
frame.add(passText);
frame.add(submit);
frame.add(reset);
frame.setSize(280, 130);
frame.setLocation(300, 200);
frame.setVisible(true);
submit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (arg0.getSource() == submit) {
LoginCheck lc = new LoginCheck(nameText.getText(), passText.getText());
System.out.println("用户名为:" + nameText.getText() + " ; 密码为: " + passText.getText());
if (lc.validate()) {
infoLab.setText("欢迎您,登录成功");
} else {
infoLab.setText("用户名或密码错误");
}
}
}
});
reset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (arg0.getSource() == reset) {
nameText.setText("");
passText.setText("");
infoLab.setText("用户登录界面");
}
}
});
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent arg0) {
System.exit(1);
}
});
}
}
public class MyActionEventDemo03 {
public static void main(String args[]) {
new ActionHandleDemo();
}
}