title: Basic Java Swing, how to exit and dispose of your application/JFrame
body: <p>What is a good way to dispose of a JFrame with code like this?  I want to handle the Window exit and window close.</p>
  
  <p>I know we shouldn't use System.exit();  </p>
  
  <pre><code>public class JavaCellularAutomataSquare {
  
    public static final String TITLE = "Cellular Automata - Squaring Example";
  
    private int maxWidth = 600;
    private int maxHeight = 600;
  
    public void launch() {    
      final JFrame frame = new JFrame(TITLE);   
      frame.setLocation(20, 20);    
      frame.setPreferredSize(new Dimension(maxWidth, maxHeight));
      frame.setResizable(false);
      frame.setFocusable(true);
  
      final JPanel panel = new JPanel();
      panel.setLocation(20, 20);
      panel.setVisible(true);
      panel.setPreferredSize(new Dimension(maxWidth, maxHeight));    
      panel.setFocusable(true);
      panel.setBackground(Color.white);
  
      // Panel setup, toggle visibility on frame
      frame.add(panel);
      frame.pack();
      frame.setVisible(true);    
    }
  
  }
  </code></pre>