Java Reference
In-Depth Information
Method
Description
public void
drawLine(
int
x1,
int
y1,
int
x2,
int
y2)
Draws a line between the point (
x1
,
y1
) and the point (
x2
,
y2
).
public void
drawRect(
int
x,
int
y,
int
width,
int
height)
Draws a rectangle of the specified
width
and
height
. The rectangle's top-left
corner is located at (
x
,
y
). Only the outline of the rectangle is drawn using the
Graphics
object's color—the body of the rectangle is not filled with this color.
public void
fillRect(
int
x,
int
y,
int
width,
int
height)
Draws a filled rectangle in the current color with the specified
width
and
height
. The rectangle's top-left corner is located at (
x
,
y
).
public void
clearRect(
int
x,
int
y,
int
width,
int
height)
Draws a filled rectangle with the specified
width
and
height
in the current
background color. The rectangle's
top-left
corner is located at (
x
,
y
). This
method is useful if you want to remove a portion of an image.
public void
drawRoundRect(
int
x,
int
y,
int
width,
int
height,
int
arcWidth,
int
arcHeight)
Draws a rectangle with rounded corners in the current color with the specified
width
and
height
. The
arcWidth
and
arcHeight
determine the rounding of the
corners (see Fig. 13.20). Only the outline of the shape is drawn.
public void
fillRoundRect(
int
x,
int
y,
int
width,
int
height,
int
arcWidth,
int
arcHeight)
Draws a filled rectangle in the current color with rounded corners with the spec-
ified
width
and
height
. The
arcWidth
and
arcHeight
determine the rounding
of the corners (see Fig. 13.20).
public void
draw3DRect(
int
x,
int
y,
int
width,
int
height,
boolean
b)
Draws a three-dimensional rectangle in the current color with the specified
width
and
height
. The rectangle's
top-left
corner is located at (
x
,
y
). The rectan-
gle appears raised when
b
is true and lowered when
b
is false. Only the outline
of the shape is drawn.
public void
fill3DRect(
int
x,
int
y,
int
width,
int
height,
boolean
b)
Draws a filled three-dimensional rectangle in the current color with the speci-
fied
width
and
height
. The rectangle's
top-left
corner is located at (
x
,
y
). The
rectangle appears raised when
b
is true and lowered when
b
is false.
public void
drawOval(
int
x,
int
y,
int
width,
int
height)
Draws an oval in the current color with the specified
width
and
height
. The
bounding rectangle's
top-left
corner is located at (
x
,
y
). The oval touches all four
sides of the bounding rectangle at the center of each side (see Fig. 13.21). Only
the outline of the shape is drawn.
public void
fillOval(
int
x,
int
y,
int
width,
int
height)
Draws a filled oval in the current color with the specified
width
and
height
.
The bounding rectangle's
top-left
corner is located at (
x
,
y
). The oval touches the
center of all four sides of the bounding rectangle (see Fig. 13.21).
Fig. 13.17
|
Graphics
methods that draw lines, rectangles and ovals.