为什么在做图形化界面时和视频里一样的但用frame f=new frame();时会抛空指针异常???frame f=new frame();与f=new frame();的区别是什么?不就返回了一个类型吗?
public class MouseAndKeyDemo{
private Frame f;
private TextField tf;
public MouseAndKeyDemo(){
inIt();
}
private void inIt(){
f=new Frame("演示用的");//........................frame f=new frame();
f.setBounds(200,400,500,400);
f.setLayout(new FlowLayout());
TextField tf=new TextField(15);
f.add(tf);
myEvent();
f.setVisible(true);
}
private void myEvent() {
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
/**
* @param args
*/
public static void main(String[] args){
// TODO Auto-generated method stub
new MouseAndKeyDemo();
}
}
|
|