I am trying to enable / disable textboxes on JOption pane depending on the user inputs, below is my code;
String input1, input2, input3, input4, input5;
input1 = "Input value 1";
input2 = "Input value 2";
input3 = "Input value 3";
input4 = "Input value 4";
input5 = "Input value 5";
field2.setEnabled(false); // this part is not working
field3.setEnabled(false); // this part is not working
field4.setEnabled(false); // this part is not working
field5.setEnabled(false); // this part is not working
JTextField field1 = new JTextField();
JTextField field2 = new JTextField();
JTextField field3 = new JTextField();
JTextField field4 = new JTextField();
JTextField field5 = new JTextField();
Object[] message = {
input1, field1,
input2, field2,
input3, field3,
input4, field4,
input5, field5,
};
int option = JOptionPane.showConfirmDialog(null, message, "Enter all your values", JOptionPane.OK_CANCEL_OPTION);
if (option == JOptionPane.OK_OPTION)
{
String value1 = field1.getText();
String value2 = field2.getText();
String value3 = field3.getText();
String value4 = field4.getText();
String value5 = field5.getText();
}
if (value1 > 0 || value1< 8) { // this part is not working
input1 = "Wrong input for value 1";
}else{
field2.setEnabled(false);
field3.setEnabled(false);
field4.setEnabled(false);
field5.setEnabled(false);
}
Basically, what I want is all the boxes to be disabled at start expect textbox 1 and if the user types in a value between 0 and 8 then it will enable the next box, else it should provide them with a error "Wrong input for value 1". I will need to do this for all the textboxes and upon the use providing the correct answer it should enable the next box.
I hope I have explained my problem correctly, if not please let me know.