Java Reference
In-Depth Information
It returns a reference to the list of transforms. To add a transform, simply add it to this list
by calling add( ) . You can clear the list by calling clear( ) . You can use remove( ) to re-
move a specific element.
In some cases, you can specify a transform directly by setting one of Node 's properties.
For example, you can set the rotation angle of a node, with the pivot point being at the cen-
ter of the node, by calling setRotate( ) , passing in the desired angle. You can set a scale
by using setScaleX( ) and setScaleY( ) , and you can translate a node by using setTrans-
lateX( ) and setTranslateY( ) . ( Z axis transforms may also be supported by the platform.)
However, using the transforms list offers the greatest flexibility, and that is the approach
demonstrated here.
To demonstrate the use of transforms, we will use the Rotate and Scale classes. (The
other transforms are used in the same general way.) Rotate rotates a node through a spe-
cified angle around a specified point. These values can be set when a Rotate instance is
created. For example, here is one Rotate constructor:
Rotate(double angle , double x , double y )
In this case, angle specifies the number of degrees to rotate. The center of rotation, called
the pivot point , is specified by x and y .
It is also possible to use the default constructor and set the rotation values after a Rotate
object has been created, which is what the demonstration program shown in the next sec-
tion will do. This is done by using the setAngle( ) , setPivotX( ) , and setPivotY( ) methods,
shown here:
final void setAngle(double angle )
final void setPivotX(double x )
final void setPivotY(double y )
As before, angle specifies the number of degrees to rotate and the center of rotation is spe-
cified by x and y . Using these methods, you can rotate a node during program execution.
This can create a very dramatic effect.
Scale scales a node as specified by a scale factor. Thus, it changes a node's size. Scale
defines several constructors. Here is the one that we will use:
Scale(double widthFactor , double heightFactor )
Search WWH ::




Custom Search