本帖最后由 杨朔 于 2012-6-23 10:49 编辑
import java.awt.*;
import java.awt.event.*;
public class FrameDemo {
private Frame f;
private Button b;
public void init(){
f.setBounds(100, 200, 200, 300);
f.setLayout(new FlowLayout());
f.setVisible(true);
f=new Frame("my frame");
b=new Button("my button");
f.add(b);
myEvent();
}
private void myEvent(){
f.addWindowListener(new WindowAdapter(){
public void windowColsing(WindowEvent e){
System.out.println("tuichu");
System.exit(0);
}
});
}
FrameDemo(){
init();
}
public static void main(String[] args) {
new FrameDemo();
}
}
Exception in thread "main" java.lang.NullPointerException
at FrameDemo.init(FrameDemo.java:10)
at FrameDemo.<init>(FrameDemo.java:33)
at FrameDemo.main(FrameDemo.java:38)
|
|