日期:2014-05-20  浏览次数:20847 次

JFrame关不掉了!
protected   void   processWindowEvent(WindowEvent   arg0)  
{
if(arg0.getNewState()==WindowEvent.WINDOW_CLOSED)
System.out.println( "ok ");
}
我想让窗口关闭时候实现一个功能!
但是现在写了这个方法以后ok不但没有执行~
窗口也关不掉了!
我想让另一个窗口激活!

------解决方案--------------------
public class MainFrame extends JFrame {
public MainFrame() {
this.setSize(400, 400);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setVisible(true);
}

public void processWindowEvent(WindowEvent e) {
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.out.println( "关闭! ");
}
super.processWindowEvent(e);
}

public static void main(String[] arags) {
new MainFrame();
}
}
------解决方案--------------------
乱七八糟的代码一大堆,不就是要实现关闭时附加动作吗!!

import java.awt.event.*;
import javax.swing.*;

public class Application extends JFrame {
private static final long serialVersionUID = 1L;

public Application() {
this.setSize(320, 300);
this.setTitle( "QQ用户注册 ");
this.setVisible(true);

this.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent arg0) {
System.out.println( "ok ");
}
});
}

public static void main(String[] args) {
new Application();
}
}

正确答案,给分给分!!!!