import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class TestFrame {
public static void main(String[] args) {
JFrame frame=new JFrame();
frame.setSize(400, 300);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
int value=JOptionPane.showConfirmDialog(null, "确定要关闭吗?");
if (value==JOptionPane.OK_OPTION) {
System.exit(0);
}
}
});
}
}