网吧计费管理系统的java程序,登录界面,管理员的用户名密码输入正确,提示“登录成功”

否则提示“登录失败”,当用户名或密码输入为空时提示“请输入用户名或密码”

AWT的一个,正确帐号密码为admin,123.
import java.awt.Button;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;

@SuppressWarnings("serial")
public class Test extends Frame {

private Button b = new Button("登录");
private Label lb1 = new Label("帐号:");
private Label lb2 = new Label("密码:");
private Label lb3 = new Label("");
private TextField t1 = new TextField("");
private TextField t2 = new TextField("");

private void addListener() {
// 按钮添加监听 判断用户登录
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionevent) {
if ("".equals(t1.getText())) {
lb3.setText("请输入帐号!");
t1.setText("");
t2.setText("");
return;
}
if ("".equals(t2.getText())) {
lb3.setText("请输入密码!");
t2.setText("");
return;
}
if (!"admin".equals(t1.getText())
|| !"123".equals(t2.getText())) {
lb3.setText("帐号或密码错误!");
t2.setText("");
return;
}
lb3.setText("登录成功!");
}
});
}

public Test() {
setTitle("网吧计费管理系统");
int y = 50;
lb1.setBounds(10, y, 40, 24);
t1.setBounds(60, y, 200, 24);
y += 30;
lb2.setBounds(10, y, 40, 24);
t2.setBounds(60, y, 200, 24);
t2.setEchoChar('*');
y += 30;
b.setBounds(160, y, 100, 30);
y += 30;
lb3.setBounds(100, y, 100, 24);

setLayout(null);
add(lb1);
add(t1);
add(lb2);
add(t2);
add(b);
add(lb3);
addListener();
}

@SuppressWarnings("deprecation")
public static void main(String[] args) throws IOException {
Test t = new Test();
t.setBounds(450, 300, 300, 200);
t.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
t.show();

}

}
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网