Java Reference
In-Depth Information
22 new KeyFrame(Duration.millis( 1000 ), eventHandler));
23 animation.setCycleCount(Timeline.INDEFINITE);
24
create a key frame
set cycle count indefinite
play animation
animation.play(); // Start animation
25
26 // Create a scene and place it in the stage
27 Scene scene = new Scene(clock, 250 , 50 );
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 }
F IGURE 15.21
A live clock is displayed in the window.
The program creates an instance clock of ClockPane for displaying a clock (line 13).
The ClockPane class is defined in Listing 14.21. The clock is placed in the scene in line 27.
An event handler is created for setting the current time in the clock (lines 16-18). This handler
is called every second in the key frame in the time line animation (lines 21-24). So the clock
time is updated every second in the animation.
15.20
How do you set the cycle count of an animation to infinite? How do you auto reverse
an animation? How do you start, pause, and stop an animation?
Check
Point
15.21
Are PathTransition , FadeTransition , and Timeline a subtype of Animation ?
15.22
How do you create a PathTransition ? How do you create a FadeTransition ?
How do you create a Timeline ?
15.23
How do you create a KeyFrame ?
15.12 Case Study: Bouncing Ball
This section presents an animation that displays a ball bouncing in a pane.
Key
Point
The program uses Timeline to animation ball bouncing, as shown in Figure 15.22.
F IGURE 15.22
A ball is bouncing in a pane.
 
 
 
Search WWH ::




Custom Search