CSCI 136: Assignment 2 -- Bouncing along

Due 2/24/97

In this assignment you are to modify the attached program to create a new bouncing object. In the code given to you the bouncing object is a solid circle. Please add a choice button which will allow you to choose what kind of an object is to be bounced. One of the choices should be an object composed of concentric (framed) circles. You should include at least one other object to be bounced. It would be interesting to see a bouncing cow or clown or spinning face or ... - use your imagination. A demo version of the program is shown below:



I have made the third choice very trivial here. I expect you can do much better.

Create (at least) two new classes which extend RenderAbsClass, and which represent these objects. The concentric circle object should look like a series of concentric circles whose radii differ by 2 pixels. In order to be able to create objects from these classes, they must implement the abstract methods in RenderAbsClass. Thus they must implement at least the following:

  protected void doRender(Component comp, Graphics g)
  public String toString()
Along with the required methods, you should include constructor for your objects with headers in the same form as:
  public Bouncer(int x, int y, int width, int height, Color color)
(presuming the name of your class is Bouncer). Thus you should be able to create these bouncer objects at any location, and having any size and color desired.

I'll leave it to you to decide exactly which fields should be included in your objects. Because your classes extend RenderAbsClass they will automatically include fields x, y, and color. Be sure not to declare them again as this will screen out the original ones. I suggest that you look at the code for classes RenderAbsClass and Rect in the Graphics library for ideas on how you might code these operations.

I found it easiest to do the drawing by overriding the methods:

  public void render(Component comp)
  public void erase(Component comp)
  public void invert(Component comp)
by having these methods set a flag (e.g., a field) before calling doRender so it can check to see which operation it should do. If you have done a good job, you will only need to change a few lines of the program BouncingBall.java. Be sure to add the files for your classes to the project BouncingBall.µ before attempting to compile and run the program.

This program is due Monday, February 24, 1997 at 11:59pm. Please label the folder containing your program, project, and classes with your name, and drag the folder to the CS136 dropoff folder on Cider Press/Courses/CS 136 folder. Your program should be fully commented (including your name). No late assignments will be accepted.