Change the java timer task execution speed

Viewed 48

I know the code looks like hell, but I'll rewrite it while I'm facing such a problem. I have a fixed task execution speed for the timer. The user changes this speed using the javafx scrollbar. Do I want to change the speed of this task for this timer? How do I do this? Here 's what I 've written so far:

timer = new Timer();
timer.schedule(new TimerTask() {
    @Override
    public void run() {
        if (i < time) {
            if (speed != (int) speedScrollBar.getValue()) {
                speed = (int) speedScrollBar.getValue();
                timer.cancel();
                timer.purge();
                runButton.setDisable(false);
              }
              else{
                  working();
              }
         }
         else{
             runButton.setDisable(false);
             timer.cancel();
             timer.purge();
         }
        }
   }, 0, speed);
0 Answers
Related