Drawing Circles

  1. Write a class Circle that represents a circle to be drawn. Store the following information in instance variables:

    Provide the following methods:

  2. Now write an application that uses your Circle class to create and draw 10 circles. This code should be fairly simple: you will need a panel class analogous to BullseyePanel in your textbook (pg. 253), and a corresponding driver class analogous to Bullseye (pg. 252). Call your panel class CirclesPanel, and the driver Circles.
  3. The paintComponent method in CirclesPanel will contain a loop having just two statements -- create a Circle, then draw it. (You can even combine them into one statement if you try!) Don't forget to pass the Graphics object to draw.
  4. Test that your program works. Notice that when you pop another window "in front of" your Circles window, that when you pop Circles back to the front, its contents change. Why is that?
  5. Add a button to your panel labelled "redraw" that causes your window to redraw its circles (10 new circles will replace the old ones.) The actionPerformed method for your button simply has to invoke repaint() to get this to work. Recall from our examples in class that your Listener class should be an inner class of your panel class. (You might want to review the LeftRight example on pp. 186-7.)
  6. Make sure your source code is properly indented and documented.