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

解决方案 »

  1.   

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Application extends JFrame
    {
    public Application() 
    {
    this.ma=ma;
    JFrame.setDefaultLookAndFeelDecorated(true);//改变感官
    this.setResizable(false);//关闭最大化
    this.setSize(320,300);//改变大小
    Setting.center(this,320,300);//居中(Setting设置类)
    this.setTitle("QQ用户注册");//改变名称
    this.setVisible(true);//显示
    }
    public static void main(String[] args) {
    Application a=new Application();
    }
    protected void processWindowEvent(WindowEvent arg0) 
    {
    if(arg0.getNewState()==WindowEvent.WINDOW_CLOSED)
    System.out.println("ok");
    }
    }
    现在这个窗口关不上了!!!
      

  2.   

    自己给自己分
    public void processWindowEvent(WindowEvent e)
    {
    if(e.getID()==WindowEvent.WINDOW_CLOSING)
    {
       this.dispose();//释放资源
       super.processWindowEvent(e);//处理此组件上发生的窗口事件
    }
    }
      

  3.   

    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();
    }
    }
      

  4.   

    好像捕捉不到 WINDOW_CLOSED!
      

  5.   

    乱七八糟的代码一大堆,不就是要实现关闭时附加动作吗!!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();
    }
    }正确答案,给分给分!!!!
      

  6.   

    JFrame jf=new JFrame("");if.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    直接关闭就行了.