title: Java Swing app won't quit
body: <p>I have a Java application that opens up a JFrame and draws in it. The problem is that when I try to quit the application, by either closing the JFrame window (on my Mac or PC) or choosing Quit from the menu bar (on my Mac), the application just hangs. What's interesting is that this behavior only appeared after I added a JButton to my application. Here's my 
  code:</p>
  
  <pre><code>public class MyApplicationFrame extends JFrame {
  
  public MyApplicationFrame(MyApplicationLogic l) {
      super();
      this.appLogic = l;
      try {
          SwingUtilities.invokeAndWait(new Runnable() {
              @Override public void run() {
                  createAndShowGUI();
              }
          });
      }
      catch(InterruptedException e) { }
      catch(InvocationTargetException e) { }
  
      g = getGraphics();
  }
  
  public void paint() { ... }
  
  private void createAndShowGUI() {
      final Container c = getContentPane();
      c.setLayout(new java.awt.FlowLayout());
  
      final JButton startButton = new JButton("Start");
              // if I comment out these lines with the startButton, everything works
      startButton.addActionListener(new ActionListener() {
          @Override public void actionPerformed(ActionEvent event) {
              appLogic.run();
              c.remove(startButton);
          }
      });
      c.add(startButton);
  
      setSize(FRAME_SIZE, FRAME_SIZE);
      setVisible(true);
      }
  }
  </code></pre>
  
  <p>In my application logic, I have the following method:</p>
  
  <pre><code>public void run() {
      appFrame.paint();
      getNextState();
  
      // then I added the following code to try and help solve this problem
      System.err.println(java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue().peekEvent());        
  }
  </code></pre>
  
  <p>The output on the System.err stream looks like this:</p>
  
  <pre>null
  null
  null
  null
  null
  // here's where I typed command-Q
  java.awt.event.MouseEvent[MOUSE_CLICKED,(210,45),absolute(210,67),button=1,modifiers=Button1,clickCount=1] on frame0
  java.awt.event.MouseEvent[MOUSE_CLICKED,(210,45),absolute(210,67),button=1,modifiers=Button1,clickCount=1] on frame0
  java.awt.event.MouseEvent[MOUSE_CLICKED,(210,45),absolute(210,67),button=1,modifiers=Button1,clickCount=1] on frame0</pre>
  
  <p>I don't have any mouse listeners in the application (although I assume that the JButton object has one) and I haven't registered any listeners other than the ActionListener on the JButton. And I didn't touch the mouse. But I assume it's all of these MouseEvents that are keeping the application from quitting. Does anybody know what I can do about this? Thanks.</p>