Creating Animation in Java

On previous days, you have drawn graphics and text by using either the paint() method in applets or the paintComponent() method in applications. These methods are used to draw something on a component whenever a program's interface needs to be redrawn. You can call a component's repaint() method to request that it be redrawn.

In most of the programs you have written thus far, these paint methods always draw the same thing—yesterday's Map applet always draws Florida in the same way when the applet window is repainted.

When creating animation, you can draw the component in its paint method, as usual. Instead of creating content that never changes, provide a way for the paint method to draw different things each time it ...

Get Sams Teach Yourself Java 2 in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.