Java Reference
In-Depth Information
The angles are numbered with zero degrees, as shown in Display 18.14. In the
first figure, the start angle is zero degrees. The counterclockwise direction is positive.
So a start angle of 90 degrees would start at the top of the oval. A start angle of
−90 degrees would start at the bottom of the oval. For example, the smile on the
happy face in Display 18.13 has a start angle of 180 degrees, so it starts on the left
end of the invisible oval. The last argument is also 180, so the arc is made visible
through a counterclockwise direction of 180 degrees, or halfway around the oval in the
counterclockwise direction.
Self-Test Exercises
10. Give an invocation of a method to draw a horizontal line from point (30, 40)
to point (100, 60). The calling object of type
Graphics
is named
g
.
11. Give an invocation of a method to draw a horizontal line of length 100 starting
at position (30, 40) and extending to the right. The calling object of type
Graphics
is named
g
.
12. Give an invocation of a method that draws a vertical line of length 100 starting
at position (30, 40) and extending downward. Use
graphicsObject
(of type
Graphic
) as the calling object.
13. Give an invocation of a method to draw a solid rectangle of width 100 and
height 50 with the upper-left corner at position (20, 30). The calling object of
type
Graphics
is named
graphicsObject
.
14. Give an invocation of a method to draw a solid rectangle of width 100 and
height 50 with the upper-right corner at position (200, 300). The calling object
of type
Graphics
is named
g
.
15. Give an invocation of a method to draw a circle of diameter 100 with the
center at position (300, 400). The calling object of type
Graphics
is named
g
.
16. Give an invocation of a method to draw a circle of radius 100 with the center
at position (300, 400). The calling object of type
Graphics
is named
g
.
Rounded Rectangles
★
A
rounded rectangle
is a rectangle whose corners have been replaced by arcs so that
the corners are rounded. For example, suppose
g
is of type
Graphics
and consider
what would be drawn by the following:
rounded
rectangle
g.drawRoundRect(x, y, width, height, arcWidth, arcHeight)
The arguments
x
,
y
,
width
, and
height
determine a regular rectangle in the usual way.
The upper-left corner is at the point (
x, y
). The rectangle has the specified
width
and