I have multiple JTextField
s and JComboBox
in my JFrame
. So whenever I click the _Add_
button it will check if the four (4) text fields in Current Medication Panel is Empty. If it is not then Execute, but it also depends if the Personal info Panel text fields are filled.
But I have a problem when I use the if and else
statement, if I use the if and else
:
if(condition if the first textfield is empty) {
// execute something like the textfield turn to red
} else if(condition if the second textfield is empty) {
// execute something like the textfield turn to red
} else if(condition if the third textfield is empty) {
// execute something like the textfield turn to red
} else{
// execute save information of the patient
}
In this situation if the 1st text field is empty then it will turn to red but if both 1st and 2nd text field is empty only the 1st text field turn to red.
I also tried the if
, and if and if but were should put the else
whenever there is no empty or invalid input where it will execute and save the patient info like this:
if(condition if the first textfield is empty) {
// execute something like the textfield turn to red
}
if(condition if the second textfield is empty) {
// execute something like the textfield turn to red
}
if(condition if the third textfield is empty) {
// execute something like the textfield turn to red
}
if(condition if the fourth textfield is empty) {
// execute something like the textfield turn to red
} else
If I use this only the last if
statement only works for the else
statement. So if the last statement is true then execute, but not then else
statement execute which is patient save info.
Is there any thing I can do about this? or is there any tutorial for me to learn more about Java and about if and else?
Aucun commentaire:
Enregistrer un commentaire