不可以。执行时候抱错: Exception occurred during event dispatching:java.lang.ClassCastException: java.util.Hashtable$Entry at maxclient.FrameMain.this_windowClosing(FrameMain.java:183) at maxclient.FrameMain$12.windowClosing(FrameMain.java:170) at java.awt.Window.processWindowEvent(Window.java:798) at javax.swing.JFrame.processWindowEvent(JFrame.java:241) at java.awt.Window.processEvent(Window.java:774) at java.awt.Component.dispatchEventImpl(Component.java:2595) at java.awt.Container.dispatchEventImpl(Container.java:1213) at java.awt.Window.dispatchEventImpl(Window.java:912) at java.awt.Component.dispatchEvent(Component.java:2499) at java.awt.EventQueue.dispatchEvent(EventQueue.java:319) at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)
那就这样吧: frameMain.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } });
dispose can be performed ,but it doese not result in the windows closing event of the child frame.
to kuky121: 你的方法不可以,是要传递主窗口的windows event to 子窗口
关闭主窗体用 System.exit(0);关闭子窗体用 setVisible(False);
to tanguanghbin: the problem is the program won't call this_windows_closing event of the sub frame while the System.exit(0) is called in the main Frame.
也就是说frameLog.dispose()会通知frameLog执行关闭动作。
Exception occurred during event dispatching:java.lang.ClassCastException: java.util.Hashtable$Entry at maxclient.FrameMain.this_windowClosing(FrameMain.java:183) at maxclient.FrameMain$12.windowClosing(FrameMain.java:170) at java.awt.Window.processWindowEvent(Window.java:798) at javax.swing.JFrame.processWindowEvent(JFrame.java:241) at java.awt.Window.processEvent(Window.java:774) at java.awt.Component.dispatchEventImpl(Component.java:2595) at java.awt.Container.dispatchEventImpl(Container.java:1213) at java.awt.Window.dispatchEventImpl(Window.java:912) at java.awt.Component.dispatchEvent(Component.java:2499) at java.awt.EventQueue.dispatchEvent(EventQueue.java:319) at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)
frameMain.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
to kuky121: 你的方法不可以,是要传递主窗口的windows event to 子窗口
the problem is the program won't call this_windows_closing event of the sub frame while the System.exit(0) is called in the main Frame.