I have a code sample with JTextField
s. When a user does not enter the details in some JTextField
, and then clicks the "Register" button, I want the user to be informed about his mistake/s. Like this:
You haven't entered Student Middle Name
or
You have not entered Student Address
or
You haven't entered Student middle name and Address
and not as
You have not entered all the details
I want the information to be in a JLabel
.
I also want that the JTextField
/s that is/are empty to have its/their background/s set as red.
I have tried many codes but none of them worked.
Here's my code. I have used the array to check which JTextField
/s are empty, but I don't know how to inform the user about them.
public void checkEmpty() {
String fname = jTextField1.getText();
String mname = jTextField2.getText();
String lname = jTextField3.getText();
String lineone = jTextField4.getText();
String linetwo = jTextField5.getText();
String linethree = jTextField6.getText();
int fnam = fname.length();
int mnam = mname.length();
int lnam = lname.length();
int lineon = lineone.length();
int linetw = linetwo.length();
int linethre = linethree.length();
int[] check = {fnam, mnam, lnam, lineon, linetw, linethre};
for (int i = 0; i < check.length; i++) {
if (check[i] == 0) {
} else {
}
}
}