Animation example

Let's look at the following code and corresponding comments:

// chapter5/basics/BasicAnimation.javapublic void start(Stage stage) {    Circle circle = new Circle(50, 150, 50, Color.RED);    // change circle.translateXProperty from it's current value to 200    KeyValue keyValue = new KeyValue(circle.translateXProperty(), 200);    // over the course of 5 seconds    KeyFrame keyFrame = new KeyFrame(Duration.seconds(5), keyValue);    Timeline timeline = new Timeline(keyFrame);    Scene scene = new Scene(new Pane(circle), 300, 250);    stage.setScene(scene);    stage.show();    timeline.play();}

It's not very convenient to show how animation works using screenshots, so I really encourage you to run the code from the preceding sample and see it in motion. ...

Get Mastering JavaFX 10 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.