java - JAVAFX, Countdown doesn't work -


The countdown does not work below, I'm triggering it through a button.

  Public Zero Startdowndowndown () {timer.schedule {New TimerTask} {@Override Public Zero Run} {Platform.runLater (New Runnabel) {Public Zero Run () {countdown- ; CountDownText.setText ("Time remaining:" + countdown); if (countdown <0) timer.cancel ();}});}}, 1000); // every 1 second}  

Countdown variable is set to 60, so the countdown starts at 60

EDIT: Countdown gets stuck in 59 seconds Countdowns do not have an int errors. And countdown text is declared as text.

  @ FXML private text countdown text;  

1 is more than a timer class, but I think you used java.util We do.

The probe of the API shows that you have used this method:

  Specified work for execution after specified zeros (timer task work, long delay) Scheduling Parameter: Task - The task is to be determined. Delay - There is a delay in milliseconds before the execution of the work. Throws: Invalid archer exception - if the delay is negative, or delay + System.currentTimeMillis () is negative. IllegalStateException - If the work was already scheduled or canceled, the timer was canceled or the timer thread was aborted. NullPointerException - If the task is zero  

then your program waits for 1 second then executes the run () method, but to repeat it not double You must use this method:

  Public Zero Schedule (TimerTasks Work, Long Delay, Long Term) Scheduling Delay delayed execution after specified designated delay. Subsequent executions are at almost regular intervals separated from the specified period. In the execution of fixed-delays, each execution is determined relative to the actual execution time of pre-execution. If any execution is delayed for any reason (such as waste collection or other background activity), the delay in execution will be delayed as well, in the long run, the frequency of execution will generally be slightly less than the reciprocal of the specified period. (The system clock is the underlying Object.wait (long) is accurate). Fixed-delay execution is suitable for recurring activities that require "smoothness". In other words, it is suitable for activities where it is more important to keep the frequency accurate in the short run than the long term. This includes most animation tasks, such as blinking a cursor at regular intervals. It also involves tasks in which regular activity is performed in response to human input, such that a key is repeated automatically, as long as the key is placed below. Parameter: Task - The task is to be determined. Delay - There is a delay in milliseconds before the execution of the work. Time in milliseconds between period-term work execution Throws: Invalid orientation exception - if there is a delay & lt; 0, or delay + System.currentTimeMillis () & lt; 0, or duration & lt; = 0 InvalidState Exception - If the task was already defined or canceled, the timer was canceled, or the timer thread was aborted NullPointerException - if the job is zero  

You can see the full document here:

Here I have the correct code:

  start the public zoomdowndown () {timer.schedule (new timerTask}} {@ override Public Video Run () {Platform.runLater (New Runnab) (Public Zero Run) (countdown -; countdown text.setT Ext ("time remaining:" + countdown "); if (count down <0) timer. Cancel ();}});}}, 1000, 1000); // every 1 second}  < / Pre> 

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -