title: WindowClosing method
body: <p>I have multiple custom dialogs and I wanted an easy way to specify the closing operation. To start with I was using the anonymous inner windowListener class and specifying the closing method that way for each dialog.</p>
  
  <p>I thought it would be more efficient to create my own class and implement the WindowListener class and specify one window closing method for all dialogs.</p>
  
  <p>So I did this and it works great. </p>
  
  <pre><code>    public class WindowWatcher implements WindowListener{
  
      @Override
      public void windowClosing(WindowEvent e) {
          System.out.println("Are you sure you wish to exit?");
           int Answer = JOptionPane.showConfirmDialog(frame, "Are you sure want to exit?", "Quit", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
              if (Answer == JOptionPane.YES_OPTION) {
                  System.exit(0);
              }
        }
  
      }
  </code></pre>
  
  <p>Note: there are other implemented method in the class.. </p>
  
  <p>Anyhow the problem I'm running in to is when I click exit, then click no, then I attempt to proceed with a dialog and say click ok.. Nothing happens. </p>
  
  <p>I understand this has something to do with the UNINITIALIZED_VALUE of the calling JOptionPane. </p>
  
  <p>I need to see the calling optionPane to this UNINITIALIZED_VALUE.  I think??</p>
  
  <p>something like: </p>
  
  <pre><code>        optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);
  </code></pre>
  
  <p>the code above assumes I have access to the optionPane however. However in my class 'WindowWatcher' class I don't have access to it. </p>
  
  <p>Any ideas how I can do this ? Perhaps I can cast e.GetSource() as a JOptionPane..</p>
  
  <p>Edit.</p>
  
  <pre><code>   ((JOptionPane)e.getSource()).setValue(JOptionPane.UNINITIALIZED_VALUE);
  </code></pre>
  
  <p>the above didn't work. "JDialog cannot be cast as a JoptionPane"</p>
  
  <p>Many Thanks!</p>