为什么我的变量仅在某些情况下激活

时间:2015-12-16 19:38:24

标签: java variables

在我的正在运行的类中,我有一个名为requestClosing的变量,当它为真时,它会打开一个新窗口并关闭旧窗口。当我点击它时,它说requestClosing是真的,但它没有做任何事情。 5秒后,我将其设置为true,它按预期工作。为什么这样做,我该如何解决?提前致谢

boolean requestClosing = false;

public void running() {
        Game game = new Game();

        if(currentTime+1000 < System.currentTimeMillis()) { //Calculates One second
            currentTime = System.currentTimeMillis();// Resets the calculations
            secondsPassed += 1; // How many seconds have passed since the last reset or start of game.
        }

        if(requestClosing) { //<-- This does not work
            try {
                windowTwo();
                loadingScreen();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        if(secondsPassed > 5 && openAllowed) {
            requestClosing = true;
            openAllowed = false;
        }
    }

0 个答案:

没有答案
相关问题