1 import javafx.application.Application;
2 import javafx.stage.Stage;
3 import javafx.animation.KeyFrame;
4 import javafx.animation.Timeline;
5 import javafx.event.ActionEvent;
6 import javafx.event.EventHandler;
7 import javafx.scene.Scene;
8 import javafx.util.Duration;
9
10 public class ClockAnimation extends Application {
11 @Override
12 public void start(Stage primaryStage) {
13 ClockPane clock = new ClockPane();
14
15
16 EventHandler<ActionEvent> eventHandler = e -> {
17 clock.setCurrentTime();
18 };
19
20
21 Timeline animation = new Timeline(
22 new KeyFrame(Duration.millis(1000), eventHandler));
23 animation.setCycleCount(Timeline.INDEFINITE);
24 animation.play();
25
26
27 Scene scene = new Scene(clock, 250, 250);
28 primaryStage.setTitle("ClockAnimation");
29 primaryStage.setScene(scene);
30 primaryStage.show();
31 }
32
33
37 public static void main(String[] args) {
38 launch(args);
39 }
40 }