Itchy Nekotorych
Itchy Nekotorych

Reputation: 992

Trying to obtain textField data on actionPerformed

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.

Upvotes: 0

Views: 108

Answers (1)

elias
elias

Reputation: 15480

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.

Upvotes: 2

Related Questions