title: How to programmatically close a JFrame
body: <p>What's the correct way to get a <code>JFrame</code> to close, the same as if the user had hit the <code>X</code> close button, or pressed <kbd>Alt</kbd>+<kbd>F4</kbd> (on Windows)?</p>
  
  <p>I have my default close operation set the way I want, via:</p>
  
  <pre><code>setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  </code></pre>
  
  <p>It does exactly what I want with the aforementioned controls.  This question isn't about that.</p>
  
  <p>What I really want to do is cause the GUI to behave in the same way as a press of <code>X</code> close button would cause it to behave.</p>
  
  <p>Suppose I were to extend <code>WindowAdaptor</code> and then add an instance of my adaptor as a listener via <code>addWindowListener()</code>.  I would like to see the same sequence of calls through <code>windowDeactivated()</code>, <code>windowClosing()</code>, and <code>windowClosed()</code> as would occur with the <code>X</code> close button.  Not so much tearing up the window as telling it to tear itself up, so to speak.</p>