title: Add actions to JPopupMenu options
body: <p>I have a class that extends JPanel and implements MouseListener. In this class, if the panel is clicked the following two functions are executed:</p>
  
  <pre><code>@Override
  public void mouseClicked(MouseEvent e) {
      displayExitPopup();
  }
  
  private void displayExitPopup() {
      JPopupMenu exitPopup = new JPopupMenu();
      exitPopup.add("Exit Game");
      exitPopup.add("Cancel");
      exitPopup.show(this, this.getWidth(), this.getHeight());
  }
  </code></pre>
  
  <p>This all works fine and the popup displays the 2 options as it should.</p>
  
  <p>Now I am trying to perform actions when either of the two options in the popup menu are clicked - <code>System.exit(0)</code> if <code>Exit Game</code> is clicked, and the popup menu to close if <code>Cancel</code> is clicked. How can this be done?</p>