Stop timer with conditional only works first time?

后端 未结 3 379
抹茶落季
抹茶落季 2021-01-21 14:38

I\'m writing a \"Who Wants to Be a Millionare\" game and I have everything set up, it\'s just a problem with the timer.

The game works like this: if the user gets the qu

3条回答
  •  面向向阳花
    2021-01-21 14:55

    What I recommend doing is moving the Timer declaration into the JFrame, and then creating a new instance of your "DisplayCountdown" class for each time the timer is needed, and move the "timer.schedule(new DisplayCountdown(), 0, 1000);" line elsewhere.

    If you purge a timer object, it is completely reset, so you don't need to create a new timer object, only add a new TimerTask.

提交回复
热议问题