java界面事件_Java 图形界面(事件处理)

/*

* 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();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值