I am trying to take the values from the text fields below to use with parent.addNewRoom(roomNo,roomEnSuite); but roomEnSuite is a Boolean value in the parent class. What is the correct procedure to get a Boolean from a JTextField?
public void actionPerformed( ActionEvent ae)
{
String item = ae.getActionCommand();
if ( item.equals("Confirm"))
{
String roomNo = nameJTextField.getText();
String roomEnSuiteS = idJTextField.getText();
parent.addNewRoom(roomNo,roomEnSuite);
this.dispose();
}
else if ( item.equals("Cancel"))
{
parent.resetButtons();
this.dispose();
}
}
To give a full answer from my above comments:
Handling
booleaninput using aJTextFieldwould not be a good way to go about things as there are many variations the user could typeyes/no/true/false, etc. mispelling?Using a
JRadioButton(for single answers) orJCheckbox(for multiple answers) would be a better way to go about handlingtrueorfalseinput. I would suggest aJRadioButtonas you wouldn’t want the user checkingtrueandfalse.http://docs.oracle.com/javase/tutorial/uiswing/components/button.html