Java Reference
In-Depth Information
22
new Line( 100 , 200 , 100 , 0 ), imageView);
23
pt.setCycleCount( 5 );
set cycle count
play animation
24
pt.play(); // Start animation
25
26 // Create a scene and place it in the stage
27 Scene scene = new Scene(pane, 250 , 200 );
28 primaryStage.setTitle( "FlagRisingAnimation" ); // Set the stage title
29 primaryStage.setScene(scene); // Place the scene in the stage
30 primaryStage.show(); // Display the stage
31 }
32 }
The program creates a pane (line 14), an image view from an image file (line 17), and places
the image view to the page (line 18). A path transition is created with duration of 10 seconds
using a line as a path and the image view as the node (lines 21 and 22). The image view will
move along the line. Since the line is not placed in the scene, you will not see the line in the
window.
The cycle count is set to 5 (line 23) so that the animation is repeated five times.
15.11.2 FadeTransition
The FadeTransition class animates the change of the opacity in a node over a given time.
FadeTransition is a subtype of Animation . The UML class diagram for the class is shown
in Figure 15.18.
The getter and setter methods for property
values and a getter for property itself are provided
in the class, but omitted in the UML diagram for brevity.
javafx.animation.FadeTransition
-duration: ObjectProperty<Duration>
-node: ObjectProperty<Node>
-fromValue: DoubleProperty
-toValue: DoubleProperty
-byValue: DoubleProperty
The duration of this transition.
The target node of this transition.
The start opacity for this animation.
The stop opacity for this animation.
The incremental value on the opacity for this animation.
+FadeTransition()
+FadeTransition(duration: Duration)
+FadeTransition(duration: Duration,
node: Node)
Creates an empty FadeTransition .
Creates a FadeTransition with the specified duration.
Creates a FadeTransition with the specified duration and node.
F IGURE 15.18
The FadeTransition class defines an animation for the change of opacity in a node.
Listing 15.14 gives an example that applies a fade transition to the filled color in an ellipse,
as shown in Figure 15.19.
L ISTING 15.14
FadeTransitionDemo.java
1 import javafx.animation.FadeTransition;
2 import javafx.animation.Timeline;
3 import javafx.application.Application;
4 import javafx.scene.Scene;
5 import javafx.scene.layout.Pane;
6 import javafx.scene.paint.Color;
7 import javafx.scene.shape.Ellipse;
8 import javafx.stage.Stage;
 
 
Search WWH ::




Custom Search