O'Reilly logo

JavaFX 2.0: Introduction by Example by Carl Dea

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3-5. Synchronizing Animation and Media

Problem

You want to incorporate animated effects in your media display. For example, you want to scroll “The End” after a video is finished playing.

Solution

Use recipe 3-3 together with recipe 2-2. Receipe 3-3 shows how to respond to media events. Recipe 2-2 demonstrates how to use javafx.animation.TranslateTransition to animate text.

The following code demonstrates an attached action when an end of a media event is triggered:

mediaPlayer.setOnEndOfMedia(new Runnable() {    @Override    public void run() {       closedCaption.setText("");       animateTheEnd.getNode().setOpacity(.90);       animateTheEnd.playFromStart();   } });

Shown here is a method that creates a translateTransition of a Text node ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required