Java codeimport javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/**
* Created by IntelliJ IDEA.
* User: admin
* Date: 2011-9-26
* Time: 16:11:50
* To change this template use File | Settings | File Templates.
*/
public class Demo1 extends JFrame {
private JButton btn=new JButton("click");
public Demo1(String title){
super(title);
this.add(btn);
this.pack();
this.setVisible(true);
this.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e) {
// super.windowClosing(e); //To change body of overridden methods use File | Settings | File Templates.
//这里写你想实现的代码,我只写了一行println
System.out.println("windowClosing");
System.exit(0);
}
});
}
public static void main(String[] args){
new Demo1("demo");
}
}