Ver Mensaje Individual
  #2 (permalink)  
Antiguo 09/02/2012, 11:46
Avatar de farfamorA
farfamorA
 
Fecha de Ingreso: noviembre-2010
Ubicación: Lima
Mensajes: 136
Antigüedad: 13 años, 5 meses
Puntos: 24
Respuesta: Preguntar antes de cerrar Ventana - Netbeans

Código Java:
Ver original
  1. public class VistaPrincipal extends javax.swing.JFrame {
  2.  
  3.     private VistaPrincipal() {
  4.         setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
  5.  
  6.         addWindowListener(new java.awt.event.WindowAdapter() {
  7.             @Override
  8.             public void windowClosing(java.awt.event.WindowEvent evt) {
  9.                 close();
  10.             }
  11.         });
  12.     }
  13.  
  14.     private void close(){
  15.         if (JOptionPane.showConfirmDialog(rootPane, "¿Desea realmente salir del sistema?",
  16.                 "Salir del sistema", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
  17.             System.exit(0);
  18.     }                
  19.  
  20. }

Salu2.