title: Swing - Closing a Frame (Window) or not depending on popup choice
body: <p>I'm trying that when a user tries to close a window in the normal way (clicking on the X) a popup shows up saying "Are you sure you want to close this window?" and then if he chooses "No", I want the window not to close, which is closing wether he chooses Yes or No.</p>
  
  <p>My current code for this listener is:</p>
  
  <pre><code>frmContactarEspecialista.addWindowListener(new FrameWindowListener());    
  
  private class FrameWindowListener extends WindowAdapter {
          @Override
          public void windowClosing(WindowEvent arg0) {
              int salir = JOptionPane.showOptionDialog(frmContactarEspecialista, "Si cierra esta ventana se descartará el email, ¿continuar?", "Salir",
                      JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
  
              if (salir != 0){
  
              }
          }
      }
  </code></pre>
  
  <p>After marking my post as duplicate, I alredy tried that with:</p>
  
  <pre><code>private class FrameWindowListener extends WindowAdapter {
          @Override
          public void windowClosing(WindowEvent arg0) {
              int salir = JOptionPane.showConfirmDialog(frmContactarEspecialista, "Si cierra esta ventana se descartará el email, ¿continuar?", "Salir",
                      JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
  
              if (salir == JOptionPane.NO_OPTION) {
                  System.out.println("do nothing");
              }
          }
      }
  </code></pre>
  
  <p>And it prints <code>"do nothing"</code> but still closes the window.</p>
  
  <p>what should I change or put into the <code>if</code> so it doesn't close the window?</p>
  
  <p>Thanks</p>