Java Reference
In-Depth Information
ticker.playFromStart();
});
Once the animation is defined, you simply invoke the play() method to get it
started. The following code snippet shows how to play a TranslateTransition:
ticker.play();
To pause and start the ticker when the mouse hovers over and leaves the text, you
need to implement similar event handlers:
// stop ticker if hovered over
tickerArea.setOnMouseEntered((MouseEvent me) -> {
ticker.pause();
});
// restart ticker if mouse leaves the ticker
tickerArea.setOnMouseExited((MouseEvent me) -> {
ticker.play();
});
Now that you have a better understanding of animated transitions, what about a
transition that can trigger any number of transitions? JavaFX has two transitions that
provide this behavior. The two transitions can invoke individual dependent transitions
sequentially or in parallel. In this recipe, you'll use a sequential transition ( Sequen-
tialTransition ) to contain two FadeTransition s in order to fade out the cur-
rent image displayed and to fade in the next image. When creating the previous and
next button's event handlers, you first determine the next image to be displayed by call-
ing the gotoImageIndex() method. Once the next image to be displayed is de-
termined, you call the transitionByFading() method, which returns an instance
of a SequentialTransition . When calling the transitionByFading()
method, you'll notice that two FadeTransition s are created. The first transition
will change the opacity level from 1.0 to 0.0 to fade out the current image, and the
second transition will interpolate the opacity level from 0.0 to 1.0, fading in the next
image, which then becomes the current image. At last the two FadeTransition s
are added to the SequentialTransition and returned to the caller. The following
code creates two FadeTransition s and adds them to a SequentialTrans-
ition :
Search WWH ::




Custom Search