Java Reference
In-Depth Information
This section presents a glimpse of the
class
Graphics
, which is contained in the
package
java.awt
. The
class
Graphics
provides methods for drawing items such
as lines, ovals, and rectangles on the screen. Some methods of the
class
Graphics
draw
shapes; others draw bitmap images. This class also contains methods to set the properties
of graphic elements including fonts and colors. Table 12-7 shows some of the construc-
tors and methods of the
class
Graphics
.
TABLE 12-7
Some Constructors and Methods of the
class
Graphics
protected
Graphics()
//Constructs a Graphics object that defines a context in which the
//user can draw. This constructor cannot be called directly.
public void
draw3DRect(
int
x,
int
y,
int
w,
int
h,
boolean
t)
//Draws a 3D rectangle at (x, y) of the width w and height h. If t is
//true, the rectangle will appear raised.
public abstract void
drawArc(
int
x,
int
y,
int
w,
int
h,
int
sangle,
int
aangle)
//Draws an arc in the rectangle at the position (x, y) of width w
//and height h. The arc starts at the angle sangle with an arc angle
//aangle. Both angles are measured in degrees.
public abstract boolean
drawImage(Image img,
int
xs1,
int
ys1,
int
xs2,
int
ys2,
int
xd1,
int
yd1,
int
xd2,
int
yd2, Color c, ImageObserver ob)
//Draws the image specified by img from the area defined by the
//bounding rectangle, (xs1, ys1) to (xs2, ys2), in the area defined
//by the rectangle (xd1, yd1) to (xd2, yd2). Any transparent color
//pixels are drawn in the color c. The ob monitors the progress of
//the image.
public abstract void
drawLine(
int
xs,
int
ys,
int
xd,
int
yd)
//Draws a line from (xs, ys) to (xd, yd).
public abstract void
drawOval(
int
x,
int
y,
int
w,
int
h)
//Draws an oval at the position (x, y) of width w and height h.
public abstract void
drawPolygon(
int
[] x,
int
[] y,
int
num)
//Draws a polygon with the points (x[0], y[0]), ...,
//(x[num - 1], y[num - 1]). Here num is the number of points in
//the polygon.
public abstract void
drawPolygon(Polygon poly)
//Draws a polygon as defined by the object poly.
public abstract void
drawRect(
int
x,
int
y,
int
w,
int
h)
//Draws a rectangle at the position (x, y) of width w and
//height h.
Search WWH ::
Custom Search