Once the objects are placed in a Stage instance and the application is executed, you should
see all four objects move up and down together on the screen, as shown in the next figure.
How it works...
The JavaFX data binding system provides an event-driven infrastructure which you can easily
use to automate object property updates. When you bind the property of a node to a single
value or an expression, the JavaFX binding system automatically registers your bound objects
to receive updates as the value (or expression) is updated. In the context of an animated
sequence, the bound object receives updates as the value (or expression), it is bound to
is interpolated by the animation engine. You can leverage this mechanism to implement
synchronized animation by binding several objects to interpolated values or expressions.
In our code snippet, we accomplish synchronized object animation with one Timeline
instance as follows:
F Declare variables —in the first portion of the code, we declare all of the variables
needed, including locY , which will be used to provide the trajectory for the
F Animated objects —next, we declare four simple shapes, including two circles and two
rectangles, that will be animated. Each shape has its y-coordinate bound to variable
locY (or an expression that uses locY ). As the value of locY changes, it will update
the position of the object along the y-axis .
F Timeline animation —all four declared objects are animated using one Timeline
instance with a single KeyFrame instance. The keyframe interpolates variable locY
from the initial value of (h - width) to width over a one-second time period.
As locY is updated by the interpolator, all four objects bound to variable locY are
animated along the y-axis.
F Chapter 1 — Using binding and triggers to update variables
F Chapter 3— Building animation with the KeyFrame API