Java线程睡眠问题

时间:2016-01-08 15:46:35

标签: java multithreading swing delay wait

我在程序中短暂延迟时遇到了一些麻烦。我想要的是系统在设置一些文本后停止约1秒但由于某种原因它不会让我设置一些文本,延迟,然后运行更多的代码。它似乎忽略了它之前的代码,只是执行以下代码。

if (event.getSource() == btnAnswer){

            if (userAnswer.equals(questions[x].correctAnswers)){
                lblQuestion.setText("Correct!");
            }
            else{
                lblQuestion.setText("Incorrect.");
            }

            try {
                Thread.sleep(1000);
            } catch(InterruptedException ex) {
                Thread.currentThread().interrupt();
            }

            userAnswer = "";

            turn +=1;
            if (turn > numOfPlayers){
                turn = 1;
            }
            lblTurn.setText(playerNames[turn] + "'s turn:");

            x = rand.nextInt(9);
            //loop stops questions from being the same one after another
            while (x == prev){
                x = rand.nextInt(9);
            }
            prev = x;

            lblQuestion.setText(questions[x].question);

等...

甚至没有显示临时文本集。

非常感谢任何建议:)

0 个答案:

没有答案