// Creates a countdown from time to 0 public Countdown(final int time) { timeLeft = new ReadOnlyIntegerWrapper(time); timeLeftDouble = new ReadOnlyDoubleWrapper(time); // Does the counting to 0 timeline = new Timeline( // start frame new KeyFrame(Duration.ZERO, new KeyValue(timeLeftDouble, time)), // end frame new KeyFrame(Duration.seconds(time), new KeyValue(timeLeftDouble, 0))); timeLeftDouble.addListener( o -> { timeLeft.set((int) Math.ceil(timeLeftDouble.get())); }); }