I want to find out why the second if statement in this code always returns false, so every time I click the 'go' button in my program it shows incorrect password. Anyone have any ideas?
package Main;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
public class CodexConsoleEngine extends CodexConsoleWindow implements ActionListener {
public void actionPerformed(ActionEvent e) {
boolean isPasswordEntered = false;
JButton clickedButton = (JButton) e.getSource();
String commandSent;
String passwordSet = "password";
char[] charPasswordEntered = password.getPassword();
String passwordEntered = charPasswordEntered.toString();
if(!isPasswordEntered){
if(passwordEntered.equals(passwordSet)){
consoleOutput.append("Correct password\n");
}else{
consoleOutput.append("Incorrect password\n");
}
}else{
consoleOutput.append("You have already entered your password");
}
}
}
Sorry for any obvious mistakes, I've only started java recently. REALLY recently.
EDIT: I've edited the code to use the .equals() method, but it still doesn't work. Could it have anything to do with the toString() method or the fact that I'm using JPasswordField?