[an error occurred while processing this directive]
[an error occurred while processing this directive]

AC26: Animation

The purpose of this activity is to learn more about programming animations. You will need to download ac26-code.zip, which contains the Java code you'll be using. If you use Eclipse, you can create a project directly from the ZIP file using File / Import / Existing Projects into Workspace / Select archive file.

1 How Not to Animate

Open Problem1.java and run it. Clicking on the window should move the rectangle through an animation from one side of the window to the other. What's wrong with the way the animation was implemented? (Hint: try to use the window's menubar while the animation is in progress.)

2 Tight Loop Animation

Open Problem2.java. Problem2 is a subclass of Problem1, and it overrides the animate() method with a different implementation that uses a tight loop to do the animation as smoothly as possible. Finish the code by filling in the part marked YOUR CODE HERE. The rectangle should follow the same path as in Problem1.

Does Problem2 suffer from the same drawback you identified in Problem1? What else is undesirable about Problem2's way of implementing animation? (Hint: look at your CPU load while the animation is running. On Windows, use the Task Manager, found by right-clicking on the taskbar. On Mac OS X, use the Activity Monitor, found in Utilities.)

3 Timer Animation

Open Problem3.java. Problem3 implements animate() using a timer. Run it and see how it works. Why does Problem3 use repaint() instead of paintImmediately()? Does Problem3 suffer from the same drawback as Problem1 and Problem2?

But it suffers from a new problem. The animation is supposed to take 2 seconds. How long does it actually take? (Instrument the code to find out.) Why?

4 Timer Animation Redux

Open Problem4.java. Problem4 is supposed to implement animate() using a timer as well as the system clock, but it's incomplete. Finish the code by filling in the part marked YOUR CODE HERE, using what you've learned from Problem2 and Problem3.

5 Animation Path

Change your Problem4 so that the rectangle follows a quadratic Bezier curve from the start point to the end point. Experiment with different control points for the curve.

[an error occurred while processing this directive]