Frame f = new Frame();
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
if (JOptionPane.showConfirmDialog(null,"是否要退出?","提示",JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION)
f.dispose();
else
f.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
}
});