开发者

java actionlistener problem

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜