public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnCancel) {
System.exit(0);
}
if (e.getSource() == btnLogin) {
int i = 0;
while (loggedIn == false) {
if (i < TeacherData.length) {
if (txtUsername.getText() == TeacherData[i].getUsername() && String.valueOf(txtPassword.getPassword()) == TeacherData[i].getPassword()) {
loggedIn = true;
System.out.println("Login Successful");
}
else {
System.out.println("Invalid Username or Password.");
i++;
}
}
}
}
}
My login panel is coded to look like this https://i.stack.imgur.com/cHoiP.jpg.
Upon pressing the "login", the button the console prints out "Invalid Username or Password." 10 times (there are 10 teachers in teacherData).
Before anybody asks I have already made sure the getUsername()
and getPassword()
methods work. txtUsername
is the name of the JTextField
and txtPassword
is the name of the JPasswordField
. I do not receive any errors.