utilizzi nel tuo JFrame:
codice:
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
ed intercetti l'evento windowclosing
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
               }
            }
        });