Ovals and Circles

Java has methods to draw outlined and filled ovals. As you'd probably guess these methods are called drawOval() and fillOval() respectively. As you might not guess they take identical arguments to drawRect() and fillRect(), i.e.

public void drawOval(int left, int top, int width, int height) 
public void fillOval(int left, int top, int width, int height)

Instead of the dimensions of the oval itself, the dimensions of the smallest rectangle which can enclose the oval are specified. The oval is drawn as large as it can be to touch the rectangle's edges at their centers. This picture may help:

oval inscribed in a rectangle

The arguments to drawOval() are the same as the arguments to drawRect(). The first int is the left hand side of the enclosing rectangle, the second is the top of the enclosing rectangle, the third is the width and the fourth is the height.

There is no special method to draw a circle. Just draw an oval inside a square.

Java also has methods to draw outlined and filled arcs. They're similar to drawOval() and fillOval() but you must also specify a starting and ending angle for the arc. Angles are given in degrees. The signatures are:

public void drawArc(int left, int top, int width, int height, 
 int startAngle, int stopAngle)
public void fillArc(int left, int top, int width, int height, 
 int startAngle, int stopAngle)

The rectangle is filled with an arc of the largest circle that could be enclosed within it. The location of 0 degrees and whether the arc is drawn clockwise or counter-clockwise are currently platform dependent.


Previous | Next | Top | Cafe au Lait

Copyright 1997-1998, 2006 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified April 26, 2006