Java Reference
In-Depth Information
Clipping Graphical Areas
To define a clipping area, we assign a Node subclass to the clip property that defines the clipping shape, in this case a
Rectangle that is 430 pixels wide and 85 pixels high. In addition to keeping the Text from covering the moon, when
the Text scrolls up as a result of animation, the clipping area keeps the Text from covering the earth.
Animating the Text to Make It Scroll Up
When the HelloEarthriseMain program is invoked, the Text begins scrolling up slowly. To achieve this animation,
we're using the TranslateTransition class located in the javafx.animation package, as shown in the following
snippet from Listing 1-1.
TranslateTransition transTransition = new TranslateTransition(new Duration(75000), textRef);
transTransition.setToY(-820);
transTransition.setInterpolator(Interpolator.LINEAR);
transTransition.setCycleCount(Timeline.INDEFINITE);
...code omitted...
// Start the text animation
transTransition.play();
The javafx.animation package contains convenience classes for animating nodes. This TranslateTransition
instance translates the Text node referenced by the textRef variable from its original Y position of 100 pixels to
a Y position of -820 pixels, over a duration of 75 seconds. The Interpolator.LINEAR constant is assigned to the
interpolator property, which causes the animation to proceed in a linear fashion. A look at the API docs for the
Interpolator class in the javafx.animation package reveals that there are other forms of interpolation available,
one of which is EASE_OUT, which slows down the animation toward the end of the specified duration.
interpolation in this context is the process of calculating the value at any point in time, given a beginning value,
an ending value, and a duration.
Note
The last line in the previous snippet begins executing the play method of the TranslateTransition instance
created earlier in the program. This makes the Text begin scrolling upward. Because of the value assigned to the
cycleCount variable, this transition will repeat indefinitely.
Now that you've compiled and run this example using the command-line tools and we've walked through the
code together, it is time to begin using the NetBeans IDE to make the development and deployment process faster
and easier.
Building and Running the Program with NetBeans
Assuming that you've downloaded and extracted the source code for this topic into a directory, follow the directions
in this exercise to build and run the Hello Earthrise program in NetBeans. If you haven't yet downloaded the Java SDK
and NetBeans, please do so from the site listed in the Resources section at the end of this chapter.
 
 
Search WWH ::




Custom Search