Java Reference
In-Depth Information
Display 18.12
Some Methods in the Class Graphics (part 3 of 3)
public abstract void fillArc( int x, int y,
int width, int height,
int startAngle, int arcSweep)
Fills the partial oval specified by
drawArc(x, y, width, height, startAngle, arcSweep)
Drawing Ovals
An oval is drawn by the method drawOval. The arguments specify the location,
width, and height of the smallest rectangle that encloses the oval. For example, the
following line draws an oval:
drawOval
g.drawOval(100, 50, 300, 200);
This draws an oval that just fits into an invisible rectangle whose upper-left corner is
at coordinates (100, 50) and that has a width of 300 pixels and a height of 200 pixels.
Note that the point that is used to place the oval on the screen is not the center of the
oval or anything like the center, but is something like the upper-left corner of the oval.
Note that a circle is a special case of an oval in which the width and height of the
rectangle are equal. For example, the following line from the definition of paint in
Display 18.11 draws a circle for the outline of the face:
g.drawOval(X_FACE, Y_FACE, FACE_DIAMETER, FACE_DIAMETER);
Because the enclosing rectangle has the same width and height, this produces a circle.
Some of the methods you can use to draw simple figures are shown in Display 18.12.
A similar table is given in Appendix 5.
Drawing Arcs
Arcs, such as the smile on the happy face in Display 18.13, are described by giving an
oval and then specifying what portion of the oval will be used for the arc. For example,
the following statement from Display 18.13 draws the smile on the happy face:
drawArc
g.drawArc(X_MOUTH, Y_MOUTH, MOUTH_WIDTH, MOUTH_HEIGHT,
MOUTH_START_ANGLE, MOUTH_ARC_SWEEP);
which is equivalent to
g.drawArc(X_MOUTH, Y_MOUTH, MOUTH_WIDTH, MOUTH_HEIGHT, 180, 180);
 
 
Search WWH ::




Custom Search