Write an Applet that draws a number of colored
shapes (e.g. round balls and square boxes) on the screen and
moves them around.
- Distinguish clearly among the model (the shapes and their
numeric properties), the view (in charge of how the shapes
are drawn on the screen), and the controller (in charge of
the dynamic user interface -- what happens in response to what user
actions).
- Implement some kind of list data structure (either roll-your-own
or using Java's built-in collection classes) so you can handle as
many shapes as the user wants.
- Provide a "new shape" button (or perhaps two, "new ball" and "new
box") that creates a new shape in addition to the ones already on
the screen. You may initialize its location and velocity with
fixed numbers, or (more fun) randomly.
- Provide a "delete shape" button that deletes one of the existing
shapes. Your program may choose which shape to delete,
e.g. the oldest or the newest, or for extra
credit you can allow the user to select which shape to
delete by clicking on it with the mouse.
- Provide a "move" button that moves all of the existing shapes as
appropriate; note that each shape should have its own velocity.
For extra credit, implement a Thread-based timer
that moves all the shapes every second (or every five seconds, or
whatever you prefer).
- When a shape reaches the edge of the screen, it should bounce
back: if it hits the right or left edge, its X velocity should be
negated, and if it hits the top or bottom edge, its Y velocity
should be negated.
- For extra credit, implement not one view but
two: the GraphicView shows all the shapes as geometric figures
moving around a Canvas, while the TableView (say, running down
the right-hand side of the screen) provides a text list
of them with types, velocities, and locations. Both views should
be automatically updated every time the shapes move. Ideally, it
should be possible for the user to select an object by mouse-clicking
on it in either view.
For convenience, here's a link
to the on-line Java API documentation.