private void windowClosing(java.awt.event.WindowEvent evt)
{
int confirmed = JOptionPane.sh
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent evt){
int x = JOptionPane.showConfirmDialog(null,
"Are you sure you want to exit ?", "Comform !",
JOptionPane.YES_NO_OPTION);
if(x == JOptionPane.YES_OPTION) {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}else{
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
}
}
});
Chek this.