-2

我有一个无限循环,它等待更新布尔值的方法,虽然这在学校似乎一切正常,但在家里却行不通。不确定这是否真的意味着它是基于计算机的还是什么,因为它也适用于那里的 print 语句。

while(running){
    //System.out.println(running);      
}

...

public static void passwordCheck(String pass){
    if(pass.equals(password)){
        correctPW = true;
    }
    else if(pass.equals(overKey))
        PWCoder.override(password);
    running = false;
}

...

public void actionPerformed(ActionEvent e){
    String temp = new String("");
    for(int x=0;x<passwordInput.getPassword().length;x++)
        temp+=passwordInput.getPassword()[x];
    PWCoder.passwordCheck(temp);
}

正如我所说,这段代码适用于未注释的 print 语句,但这相当难看。我要在这里输入一个密码屏幕,如果您输入错误,则会打开一个不同的窗口(代码未显示),或者您可以输入调用覆盖方法的覆盖密码。我使用了许多调试语句,在方法中运行设置为 false,我猜 while 循环只是没有选择它。抱歉,代码有点乱。While 循环有问题,应该让循环结束的方法,以及调用所述方法的另一个类中的方法。

4

1 回答 1

0

A number of issues, this should work

 public static void passwordCheck(String pass){
        if(pass.equals(password)){
            correctPW = true;
            running = true;
        }
        else if(pass.equals(overKey)) {
            PWCoder.override(password);
        running = false;
    }
    }

Also, you may consider just using break, to get out of your loop on success.

于 2013-03-05T16:52:51.773 回答