如何用JAVA编程编写一个界面程序(急求!!!)
我下面写了一个,初始账号和密码是 nihao 5201314 你可以改或设置
import java.awt.*;
import java.awt.event.*;
class MyDow extends Frame implements ActionListener{
private Label lName,lPassword;
private TextField tName,tPassword;
private Button login,rest,exitout;
private Label login_clew;
private int count=0;
private String myName="nihao";
private String myPassword="5201314";
public void setMyNP(String n,String p){
myName=n;
myPassword=p;
}
public MyDow(String str){
super(str);
}
public void init(){
setLayout(null);
setSize(400,300);
setVisible(true);
setResizable(false);
lName=new Label("姓名");
lName.setBounds(50, 70, 60, 30);add(lName);
lPassword=new Label("密码");
lPassword.setBounds(50, 120, 60, 30);add(lPassword);
tName=new TextField("");
tName.setBounds(110, 70, 200, 30);add(tName);
tPassword=new TextField("");
tPassword.setBounds(110, 120, 200, 30);add(tPassword);
login=new Button("登录");
login.setBounds(90, 200, 60, 30);add(login);
rest=new Button("重输");
rest.setBounds(170, 200, 60, 30);add(rest);
exitout=new Button("退出");
exitout.setBounds(250,200,60,30);add(exitout);
login_clew=new Label("");
login.addActionListener(this);
rest.addActionListener(this);
exitout.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==login){
if(count<2){
if(tName.getText().equalsIgnoreCase(myName)&&tPassword.getText().equalsIgnoreCase(myPassword)){
removeAll();
add(login_clew);
add(exitout);
exitout.setLabel("确定");
login_clew.setBounds(160,120,200,30);
login_clew.setText("欢迎XX用户!");
exitout.setBounds(170,220,60,30);
}else{
add(login_clew);
login_clew.setBounds(90,160,200,30);
login_clew.setText("请输入正确的信息!");
count++;
}
}else{
add(login_clew);
login_clew.setBounds(90,160,200,30);
login_clew.setText("你输入的次数达到了3次,不能登录了!");
}
}else if(e.getSource()==exitout){
System.exit(1);
}else{
lName.setText("");
lPassword.setText("");
}
}
}
public class UserLogin {
public static void main(String args[]){
MyDow m=new MyDow("登录窗口");
m.init();
}
}
广告 您可能关注的内容 |