title: Adding action to JOptionPane buttons
body: <p>I have an error dialog box show up when a user puts in bad login information (bad password/username). </p>
  
  <p>I created the error box using a <code>JOptionPane</code>, but the "Ok" button doesn't do anything. </p>
  
  <p>I can't figure out how to access the button to call <code>dispose()</code> or something on that particular dialog box. </p>
  
  <p>Here is what i have:</p>
  
  <pre><code>final JDialog error = new JDialog();
  error.setTitle("Login Failed");
  final JOptionPane optionPane = new JOptionPane(
          "Invalid Username/Password",
          JOptionPane.INFORMATION_MESSAGE);
  error.add(optionPane);
  
  optionPane.actionPerformed(new ActionPerformed() {
  
      public void actionPerformed(ActionEvent e)
      {
          error.dispose();
      }
  });
  error.setLocation(100,100);
  error.setSize(new Dimension(300,150));
  error.setModal(true);
  error.setVisible(true);
  </code></pre>
  
  <p>Please help. </p>