utilizzi nel tuo JFrame:
ed intercetti l'evento windowclosingcodice:setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
codice:addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if(JOptionPane.showConfirmDialog(new JFrame(),"Exit?","AppSample", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){ System.exit(0);//se premi YES chiudi la tua app }else{ //non fa nulla } } });