Add actionlistener to a button in joptionPane (java)
问题 How can I add ActionListener to a JButton in JOptionPane . So that when I press on the button, it excutes a certain code. I tried to use this code, but it is not working: 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