In this lab we will continue to explore the idea of loops (
for loops in Java) by
writing a simple animation, as in the samples from lecture. You should write an animation
which draws a number of simple moving objects through multiple frames. This
amounts to repeatedly painting the objects in a DrawingPanel, pausing and clearing the
picture between each "frame". You can use the drawing panels
to pause for a specified number of milliseconds.
You will need to define two files, one to hold your
main() method and the various
variables used for the drawing, and one to define some sort of objects to move and draw.
You should choose a class of objects which have at least a couple of parts (i.e., not
just the Balls from the lecture example).
Some examples might include cars, kites, human figures, smiley faces, animals of some sort,
even constellations (!). You will need to paint the objects using the various methods of the
Graphics class: see this listing
for documentation of the methods available. (I don't recommend trying to use the
drawImage methods yet, but for example
fillPoly might be useful.)
You may have your objects move in any fashion you wish, but there should be some variation among them (for example, our balls in class had different initial velocities). They should, however, move on their own, i.e., they should have a move method with no parameters. This means that any velocities, gravity effects, etc., should be contained in the objects themselves.
If you wish to make your animation a bit more interesting, you might use different classes of objects, or perhaps use other variables to cause your objects to shrink or grow over time, or to changes their behavior or appearance (e.g., color) when they reach some physical boundary. None of these extras is required, but you are encouraged to explore in order to practice and have fun!