Java Reference
In-Depth Information
Developer Tip:
The
Rectangle
shape encapsulates the
Text
object and allows
for the user to have a larger area to click the mouse. This area is the full width and
height of the entire text. If this
Rectangle
were not present, then the user would
have been restricted to clicking the mouse right over the painted parts of the indi-
vidual letters of the
Text
. For example, clicking inside the letter O would not
work; you would have to click on the black part of the letter O. Otherwise, the
mouse events would not be delivered to the
HyperText
object.
The
javafx.scene.shapes
package contains numerous shape types. We have
already seen
Rectangle
and
Circle
in action in some of the previous examples.
The other shapes are
Line
,
Arc
,
Ellipse
,
Polygon
,
CubicCurve
, and
QuadCurve
.
Polygon
An example of a triangle using a polygon centered within the scene is shown in
the following code and in Figure 5.23.
Polygon {
translateX: bind scene.width/2
translateY: bind scene.height/2
scaleX: 4
scaleY: 4
rotate: 45
points: [ 0, -10, 10, 10, -10, 10, 0, -10]
fill: Color.RED
}
Figure 5.23
Triangle - Scaled 4u, Rotated 45 Degrees
Line
A line draws a line between two points (see Figure 5.24).
Search WWH ::
Custom Search