Projects 4 - 5 -- bouncing balls.


Project 4:

Draw a light-blue, rectangular table, occupying most of the screen.
Three colored balls (RED, GREEN, BLUE), each with random horizontal and vertical velocities (dx and dy), bounce off the boundaries (left, top, right, bottom) of the rectangle.

When the mouse is clicked INSIDE the rectangle, re-start all three balls at the left side, EACH one with a random height and random velocities (dx and dy).
Also, respond as follows when a key is pressed:

Display a (rectangular) button.
The first time this button is clicked, change the table to another color;
if it is clicked again, change table back to original color.
(Original color, if clicked an even number of times; otherwise, use the new color.)


Project 5:     Use a   Ball   class.

Define a class named "Ball" (with a Capital "B"), with appropriate properties and methods, and redo Project 4 (as "Project 5") using this class (instead of global variables and functions).

Each instance of a Ball should be named with the color (red, green, blue) followed by your own Last name. If your Last name is "Smith" then the instances should be named:

Also create a class named "Button" (with a Capital "B"), and make four buttons, displaying the following text and performing the following actions when clicked: The "Button" class should have the following methods:
    void show() {
    // Display this button.

    boolean isHit( float x, float y ) {
    // Return "true" if (x,y) is within this button's rectangle.