title: How do stop exit program when clicking the red cross in JFrame title bar
body: <p>I have a simple java GUI application, which will prompt a user for a message like "Are you sure you want to quit?", before he quits the program. Though this only works when I use my Exit Program JButton, but when I use the red cross in the JFrame title bar, then it doesn't matter if I click either yes or no in the message dialog window.</p>
  
  <p>For this task I have added a new WindowListener to my JFrame, with this code</p>
  
  <pre><code>frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent evt) {
          int Answer = JOptionPane.showConfirmDialog(frame, "You want to quit?", "Quit", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
          if (answer == JOptionPane.YES_OPTION) {
              System.exit(0);
          }
      }
  });
  </code></pre>
  
  <p>If I click no, the program exits anyway, how can I stop that action?</p>