title: Add actionlistener to a button in joptionPane (java)
body: <p>How can I add <code>ActionListener</code> to a <code>JButton</code> in <code>JOptionPane</code>. So that when I press on the button, it excutes a certain code. 
  I tried to use this code, but it is not working:</p>
  
  <pre><code>JButton button1= new JButton("Button 1");
  int value = JOptionPane.showOptionDialog(null, "Here's a test message", "Test", JOptionPane.YES_OPTION , JOptionPane.QUESTION_MESSAGE, null,new Object[]{button1}, button1);
  button1.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
          //code to excute
          System.out.println("code excuted");
      }
  }); 
  </code></pre>