开发者

java actionlistener problem

开发者 https://www.devze.com 2023-01-25 12:46 出处:网络
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 s

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号