enter image description here

Seconds do not decrease, the program immediately after pressing the button gives those numbers "1:03", and nothing else. I tried to remove the break, gives "0: 0."

public void TIMER_funk(int sec) { timer_sec.schedule(new TimerTask() { @Override public void run() { Platform.runLater(new Runnable() { @Override public void run() { int seconds = sec; while (--seconds > 0) { MINUTES.setText(String.valueOf(seconds / 60)); SECONDS.setText(String.valueOf(seconds % 60)); break; } if(seconds % 60==1||seconds % 60==2||seconds % 60==3||seconds % 60==0){ SECONDS.setTextFill(Color.RED);}else{SECONDS.setTextFill(Color.BLACK);} if(seconds % 60==1||seconds % 60==2||seconds % 60==3||seconds % 60==4||seconds % 60==5||seconds % 60==6|| seconds % 60==7||seconds % 60==8||seconds % 60==9){ SECONDS.setText("0"+String.valueOf(seconds % 60)); } } }); } }, 1000, 1000); } 

MISTAKE!!! GIVES AN ERROR MESSAGE enter image description here

    1 answer 1

    Sort of:

     public void TIMER_funk(int sec) { seconds_left = sec; timer_sec.schedule(new TimerTask() { @Override public void run() { Platform.runLater(new Runnable() { @Override public void run() { if (seconds_left> 0) { seconds_left--; int minutes = seconds_left / 60; int seconds = seconds_left % 60; SECONDS.setTextFill(seconds < 4 ? Color.RED : Color.BLACK); MINUTES.setText((minutes < 10?"0":"") + minutes); SECONDS.setText((seconds < 10?"0":"") + seconds); } } }); } }, 1000, 1000); } 

    I think it is also worthwhile to provide a stop timer event upon reaching zero.

    • Thank you very much, but it gives an error. - Kolia
    • Well, copy the argument to the class field. Or even transfer - vp_arth
    • Thank you, you saved me. - Kolia
    • @Kolia, the main thing is that this is not a test task for hiring;) - vp_arth
    • )) Thanks teacher, you are a sage of the 21st century, so many answers were given to people. - Kolia