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 // Override the start method in the Application class
 12    public void start(Stage primaryStage) {
 13      ClockPane clock = new ClockPane(); // Create a clock
 14  
 15      // Create a handler for animation
 16      EventHandler<ActionEvent> eventHandler = e -> {
 17        clock.setCurrentTime(); // Set a new clock time
 18      };
 19      
 20      // Create an animation for a running clock
 21      Timeline animation = new Timeline(
 22        new KeyFrame(Duration.millis(1000), eventHandler));
 23      animation.setCycleCount(Timeline.INDEFINITE);
 24      animation.play(); // Start animation
 25      
 26      // Create a scene and place it in the stage
 27      Scene scene = new Scene(clock, 250, 250);
 28      primaryStage.setTitle("ClockAnimation"); // Set the stage title
 29      primaryStage.setScene(scene); // Place the scene in the stage
 30      primaryStage.show(); // Display the stage
 31    }
 32  
 33    /**
 34     * The main method is only needed for the IDE with limited
 35     * JavaFX support. Not needed for running from the command line.
 36     */
 37    public static void main(String[] args) {
 38      launch(args);
 39    }
 40  }