0
JOptionPane.showConfirmDialog(null, instructorEditorPanel,
              "Edit Player JOptionPane", JOptionPane.OK_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE);

instructorEditorPanel is a Jpanel with 3 textfields. I am trying to obtain the data in the textFields and assign them to instance variables within the parent class. I know how to get the data using the getText() method. My problem is rigging the handler to perform an action when the OK button is selected.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Itchy Nekotorych
  • 882
  • 3
  • 10
  • 24
  • I think I have initialize a variable with the statement, then make an If then statement that if true will initiate the instance variables; I am trying that out now will let you know if works out. – Itchy Nekotorych Apr 17 '12 at 17:16

1 Answers1

2

In this case, the showConfirmDialog() will return 0 when click the OK button. You can do something like this:

if(JOptionPane.showConfirmDialog(null, instructorEditorPanel, "Edit Player JOptionPane", OptionPane.OK_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION){
    //do something with value
    fieldOnPanel.getText();
}

Obviously, you need to have access to the JPanel or the JTextField instance.

elias
  • 15,010
  • 4
  • 40
  • 65
  • 3
    Instead of comparing the return value to 0, compare it to `JOptionPane.OK_OPTION`. (True, that is zero, but a TA/Professor/Instructor might ding you for using magic numbers.) – Jason Braucht Apr 17 '12 at 17:25