Java Reference
In-Depth Information
(x, y)
(x, y)
h
h
w
w
(a) Plain rectangle
(b) Filled rectangle
F
IGURE
13.6
(a) The
drawRect(x, y, w, h)
method draws a rectangle. (b) The
fillRect(x, y, w, h)
method
draws a filled rectangle.
(x, y)
aw/2
ah/2
(x, y)
h
h
w
w
(a)
drawRoundRect
(b)
drawOval
F
IGURE
13.7
(a) The
drawRoundRect(x, y, w, h, aw, ah)
method draws a round-
cornered rectangle. (b) The
drawOval(x, y, w, h)
method draws an oval based on its
bounding rectangle.
In other words,
aw
and
ah
are the width and the height of the oval that produces a quarter-
circle at each corner.
The
draw3DRect(int x, int y, int w, int h, boolean raised)
method
draws a 3-D rectangle and the
fill3DRect(int x, int y, int w, int h, boolean
raised)
method draws a filled 3-D rectangle. The parameters
x
,
y
,
w
, and
h
are the same as
in the
drawRect
method. The last parameter, a Boolean value, indicates whether the rectan-
gle is raised above the surface or sunk into the surface.
Depending on whether you wish to draw an oval in outline or filled solid, you can use
either the
drawOval(int x, int y, int w, int h)
method or the
fillOval(int x,
int y, int w, int h)
method. An oval is drawn based on its bounding rectangle. Para-
meters
x
and
y
indicate the top-left corner of the bounding rectangle, and
w
and
h
indicate the
width and height, respectively, of the bounding rectangle, as shown in Figure 13.7b.
draw3DRect
fill3DRect
drawOval
fillOval
✓
✓
13.6
Describe the methods for drawing strings, lines, and the methods for drawing/filling
rectangles, round-cornered rectangles, 3-D rectangles, and ovals.
13.7
Draw a thick line from (
10
,
10
) to (
70
,
30
). You can draw several lines next to each
other to create the effect of one thick line.
13.8
Draw/fill a rectangle of width
100
and height
50
with the upper-left corner
at (
10
,
10
).
13.9
Draw/fill a round-cornered rectangle with width
100
, height
200
, corner horizontal
diameter
40
, and corner vertical diameter
20
.
13.10
Draw/fill a circle with radius
30
.
13.11
Draw/fill an oval with width
50
and height
100
.
Check
Point