title: How can I close a JFrame by click on a button?
body: <p>I would like to have a button in my window such that if I click it (button) the window is closed.</p>
  
  <p>I found out that I can close a window in the following way:</p>
  
  <pre><code>referenceToTheFrame.hide(); //hides the frame from view
  refToTheFrame.dispose(); //disposes the frame from memory
  </code></pre>
  
  <p>But if I do this way, compiler complains:</p>
  
  <pre><code>Note: myProgram.java uses or overrides a deprecated API
  Note: Recompile with -Xlint:deprication for details.
  </code></pre>
  
  <p>Do I do something unsafe?</p>