登入界面的问题
登入界面的问题 测试下按钮能不能对事件作出反应,就是点一下登入按钮 把名字换成确定就可以了结果可以运行 但按登入的时候抛出异常不知道什么原因 请高手指点下
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class login extends WindowAdapter implements ActionListener,WindowListener{
Frame frame;
Panel pan1;
Panel pan2;
Panel pan3;
TextField text1;
TextField text2;
Label user;
Label psw;
Button ok;
Button cancel;
public login(){
Frame frame =new Frame("用户登入");
frame.setSize(200,200);
frame.addWindowListener(this);
Panel pan1=new Panel();
Panel pan2=new Panel();
Panel pan3=new Panel();
Label user=new Label("用户名");
Label psw=new Label("密码") ;
TextField text1=new TextField(12);
TextField text2=new TextField(12);
Button ok=new Button("登入");
Button cancel=new Button("取消");
ok.addActionListener(this);
frame.setLayout(new GridLayout(3,1,10,20));
pan1.add(user);
pan1.add(text1);
pan2.add(psw);
pan2.add(text2);
pan3.add(ok);
pan3.add(cancel);
frame.add(pan1);
frame.add(pan2);
frame.add(pan3);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e){
ok.setLabel("I have been pressed");
}
public void windowActivated(WindowEvent e){};
public void windowClosed(WindowEvent e){};
public void windowClosing(WindowEvent e){
System.exit(0);
}
public void windowDeactivated(WindowEvent e){};
public void windowDeiconified(WindowEvent e){};
public void windowIconified(WindowEvent e){};
public void windowOpened(WindowEvent e){};
public static void main (String[] args) {
login uid=new login();
}
}