Java Reference
In-Depth Information
39 arc4.setStroke(Color.BLACK);
40 pane.getChildren().add(
new
Text(
210
,
170
,
"arc4: chord"
));
41 pane.getChildren().add(arc4);
42
43
// Create a scene and place it in the stage
44 Scene scene =
new
Scene(pane,
300
,
200
);
45 primaryStage.setTitle(
"ShowArc"
);
// Set the stage title
46 primaryStage.setScene(scene);
// Place the scene in the stage
47 primaryStage.show();
// Display the stage
48 }
49 }
add
arc4
to pane
The program creates an arc
arc1
centered at (
150
,
100
) with
radiusX 80
and
radiusY 80
.
The starting angle is
30
with
length 35
(line 15).
arc1
's arc type is set to
ArcType.ROUND
(line 18). Since
arc1
's fill color is red,
arc1
is displayed filled with red round.
The program creates an arc
arc3
centered at (
150
,
100
) with
radiusX 80
and
radiusY 80
.
The starting angle is
30+180
with
length 35
(line 29).
Arc3
's arc type is set to
ArcType.
CHORD
(line 31). Since
arc3
's fill color is white and stroke color is black,
arc3
is displayed
with black outline as a chord.
Angles may be negative. A negative starting angle sweeps clockwise from the easterly
direction, as shown in Figure 14.37. A negative spanning angle sweeps clockwise from the
starting angle. The following two statements define the same arc:
negative degrees
new
Arc(x, y, radiusX, radiusY,
-30
,
-20
);
new
Arc(x, y, radiusX, radiusY,
-50
,
20
);
The first statement uses negative starting angle
-30
and negative spanning angle
-20
, as
shown in Figure 14.37a. The second statement uses negative starting angle
-50
and positive
spanning angle
20
, as shown in Figure 14.37b.
-30
-20
-50
20
(a) Negative starting angle -30
and
negative spanning angle -20
(b) Negative starting angle -50
and positive spanning angle 20
F
IGURE
14.37
Angles may be negative.
Note that the trigonometric methods in the
Math
class use the angles in radians, but the
angles in the
Arc
class are in degrees.
14.11.6
Polygon
and
Polyline
The
Polygon
class defines a polygon that connects a sequence of points, as shown in
Figure 14.38a. The
Polyline
class is similar to the
Polygon
class except that the
Polyline
class is not automatically closed, as shown in Figure 14.38b.
Search WWH ::
Custom Search