The Java Course provides a general introduction to programming in Java. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details.


Other Drawing Commands

Another drawing command with the same parameters as drawOval is

    drawRect (int x, int y, int width, int height)

Here I am using a standard format for documenting the name and parameters of methods. This information is sometimes called the method's interface or prototype. Looking at this prototype, you can tell what types the parameters are and (based on their names) infer what they do. Here's another example:

drawLine (int x1, int y1, int x2, int y2)

The use of parameter names x1, x2, y1 and y2 suggests that drawLine draws a line from the point (x1, y1) to the point (x2, y2).

One other command you might want to try is

drawRoundRect (int x, int y, int width, int height,
           int arcWidth, int arcHeight)

The first four parameters specify the bounding box of the rectangle; the remaining two parameters indicate how rounded the corners should be, specifying the horizontal and vertical diameter of the arcs at the corners.

There are also "fill" versions of these commands, that not only draw the outline of a shape, but also fill it in. The interfaces are identical; only the names have been changed:

fillOval (int x, int y, int width, int height)
fillRect (int x, int y, int width, int height)
fillRoundRect (int x, int y, int width, int height,
           int arcWidth, int arcHeight)

There is no such thing as fillLine---it just doesn't make sense.



Last Update: 2011-01-24