请教如何关闭窗口?
import java.awt.*;
import java.awt.event.*;
public class WindowEvent
{
public static void main(String argv[])
{
Frame f=new Frame( "window event text ");
f.addWindowListener(new WindowEventHandler());
f.setSize(400,300);
f.setVisible(true);
}
}
class WindowEventHandler extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.out.println( "window closing event ");
System.exit(0);
}
}
为什么按了红叉仍然关不掉窗口?
------解决方案--------------------是这样的:public class WindowEvent,这个你自己定义的类覆盖了原来的WindowEvent,所以在
public void windowClosing(WindowEvent e)中WindowEvent 已经不再是你期望的WindowEvent 了,把名字改成WindowEvent123即可
------解决方案--------------------你的类名和java.awt.event.WindowEvent冲突了。
换个类个,或者把方法改为:public void windowClosing(java.awt.event.WindowEvent e) { ... }
------解决方案--------------------你原来名字的类已经编译过了,class文件已经存在,你没有删除它,所以类名冲突还是存在的,找找当前目录下是否有WindowEvent.class文件,把它删掉。