In JavaFX, how can I display values which continuously change with time using \"label\" ?
Excellent responses, thank you jewelsea for your input it helped me a lot.
I updated the DigitalClock posted previously in a leaner format using Java 8. Using the additions of Java 8 like Date API and of course the lambdas.
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.scene.control.Label;
import javafx.util.Duration;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
public class DigitalClock extends Label
{
private static DateTimeFormatter SHORT_TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss");
public DigitalClock()
{
bindToTime();
}
private void bindToTime() {
Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(0),
event -> setText(LocalTime.now().format(SHORT_TIME_FORMATTER))),
new KeyFrame(Duration.seconds(1)));
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
}
}