Im trying to make a symple login system using swingf, I am having some trouble with if statements to check the login details if you can find any falts in my code that would be great :)(the second if statement does not fire if test is entered in the text box )
public void actionPerformed(ActionEvent e)
{
if ((e.getSource()) == loginBut开发者_开发技巧ton)
{
login();
}
}
public void login()
{
String test = loginField.getText();
System.out.println(test);
if (test == "test")
{
System.out.println(test);
}
}
It looks like you are trying to compare the String test to "test".
In Java, you compare two strings like this:
if (test.equals("test")) {
the == operator will only return true if both strings are the EXACT same object.
精彩评论