Lab 9 Post-Lab Assignment: Drawing Circles
Due Friday, November 8, 2002
Write a Circle class that stores the following information as
Your Circle class should provide the following
- x coord of upper left-hand corner
- y coord of upper left-hand corner
- A parameterless constructor that generates random values for the
radius, color, x, and y. Make the radius between 100 and 200, x between
0 and 600, y between 0 and 400. The circles can be any color --
note that you can pass a single int parameter to the Color constructor, but
it will only consider the first 24 bits. So when generating a random color,
you should generate something in the range 0..
224-1 = 16777215.)
IMPORTANT: Your random number generator must be declared at the class
level (not inside the constructor), and must be declared static. So
its declaration and initialization
should appear with the declarations of radius, color, x, and y, and
should look like this:
private static Random generator = new Random();
- A draw method that draws the circle at its x,y coordinate in its
color. Note that you need a Graphics object to draw (like the
page parameter of the paint method), so your draw method
will have to take a Graphics object as a parameter.
When your Circle class compiles, write an applet DrawCircles that
uses your Circle class to create and draw 10 circles.
This code should be very simple; the
paint method will contain a loop with just two statements -- create
a Circle, then draw it. Don't forget to pass the Graphics object to
Be sure your program is appropriately documented.
- Hard copy of your program.
- Tar your post lab directory that contains all of your files (.java,
.class, and .html) and email it to your instructor with
cpsc120 post9 in the subject line.