import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class AwtDemo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Frame f = new Frame("纠结");
f.setLayout(new FlowLayout());
f.setSize(300, 300);
Button b = new Button("哈哈哈");
f.add(b);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.out.println("关闭了");
System.exit(0);
}
public void windowActivated(WindowEvent e){
System.out.println("窗口被激活了");
}
public void windowOpened(WindowEvent e)
{
System.out.println("哈哈哈哈");
}
});
f.setVisible(true);
}
} 大家注意看,不知道大家注意到这个问题没有我把红色的语句放到最后面,整个程序都执行正常,但是把程序放到前面
public void windowOpened(WindowEvent e)
{
System.out.println("哈哈哈哈");
}
这个语句就不会执行啊
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class AwtDemo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Frame f = new Frame("纠结");
f.setLayout(new FlowLayout());
f.setSize(300, 300);
Button b = new Button("哈哈哈");
f.add(b);
f.setVisible(true);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.out.println("关闭了");
System.exit(0);
}
public void windowActivated(WindowEvent e){
System.out.println("窗口被激活了");
}
// public void windowOpened(WindowEvent e){
// System.out.println("窗口打开了");
// }
public void windowOpened(WindowEvent e)
{
System.out.println("哈哈哈哈");
}
});
}
}
|