快给分吧!
import java.awt.event.*;
import javax.swing.*;
public class XDialog extends JDialog{
public XDialog(){
super(new JFrame(), "Test");
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
int nRet = JOptionPane.showConfirmDialog((JDialog)e.getWindow(), "Are you sure?", "Test", JOptionPane.YES_NO_OPTION);
if ( nRet == JOptionPane.YES_OPTION){
dispose();
}
}
});
}
public static void main(String[] args){
XDialog xd = new XDialog();
xd.show();
}
}