Java Reference
In-Depth Information
There's more...
There are other basic, though irregular, geometric shapes available from the JavaFX Shape
toolbox. Polyline and Polygon classes can be used to create shapes by connecting line
segments together. The Arc class creates circular shapes by specifying points on angular
path. Let's take a closer look at them.
Polyline and Polygon
The Polyline (and the Polygon ) class creates shapes by specifying a collection of
coordinates to create line segments that are automatically connected. The Polygon class
works the same way. However, the Polygon class will also close the shape after the last
segment is drawn and fill it with a color (default is black). The Polygon code segment given
next draws a triangle, as shown in the figure alongside. The full listing of the code can be
found in ch002/source-code/src/shapes/PolygonShape.fx .
Polygon {
points: [
10.0, 10.0,
100.0, 100.0,
0.0, 100.0,
10.0, 10.0
]
}
Arc
The Arc shape class draws an arc by specifying the center coordinates, vertical/horizontal
radii, the start angle (in degrees), and the angular length (in degrees) of the arc. The arc
shape is automatically closed and filled in with a specified color (the default is black). The
next code segment draws the arc shown in the figure alongside (Pacman anyone?). The full
listing of the code can be found in ch002/source-code/src/shapes/ArcShape.fx .
Arc {
centerX: 300 centerY: 50
radiusX: 50 radiusY: 50
startAngle: 45
length: 270
type: ArcType.ROUND
}
Search WWH ::




Custom Search