I'm working on a login screen for my game, and everything works fine, except for one thing. When I check to see if the text from the JTextField == "", it still launches the game and whatnot.
Here's a look at my code:
public void attemptLogin(String username, String passcode) {
if (username != "" && passcode != "") {
System.out.println(username);
System.out.println(passcode);
} else if (username == " " || passcode == " ") {
JOptionPane.showMessageDialog(null, "Put in your credentials!", "Hey you!", JOptionPane.ERROR_MESSAGE);
}
}
}
In my main class, it goes:
public void actionPerformed(ActionEvent action) {
if (action.getSource() == login) {
gamelogin.attemptLogin(username.getText(), passcode.getText());
} else if (action.getSource() == register) {
account.registerAccount();
}
}
Now what must happen is that if the JTextField comes up blank, then show a JOptionPane and if not, login to the game (added later), but evidently, this is not happening. It just outputs white space in the console.
Thanks in advance! :)