title: close java frame using code
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1234912/how-to-programmatically-close-a-jframe">How to programmatically close a JFrame</a>  </p>
  </blockquote>
  
  
  
  <p>I am developing a java GUI using JFrame. I want to close the GUI frame and dispose it off through code.
  I have implemented :</p>
  
  <pre><code>topFrame.addWindowListener(new WindowListener()
          {
              public void windowClosing(WindowEvent e)
              {
                  emsClient.close();
              }
              public void windowOpened(WindowEvent e) {
              }
              public void windowClosed(WindowEvent e) {
              }
              public void windowIconified(WindowEvent e) {
              }
              public void windowDeiconified(WindowEvent e) {
              }
              public void windowActivated(WindowEvent e) {
              }
              public void windowDeactivated(WindowEvent e) {
              }
          });`
  </code></pre>
  
  <p>How can I invoke the windowClosing event?? Or is there some other way?</p>