24.3 Animating a Series of Images

Next, we animate a series of images stored in an array of ImageIcons. In this example, we use the JNLP FileOpenService to enable the user to choose a group of images that will be animated by displaying one image at a time at 50-millisecond intervals. The animation presented in Figs. 24.424.5 is implemented using a subclass of JPanel called LogoAnimatorJPanel (Fig. 24.4) that can be attached to an application window or a JApplet. Class LogoAnimator (Fig. 24.5) declares a main method (lines 8–20 of Fig. 24.5) to execute the animation as an application. Method main declares an instance of class JFrame and attaches a LogoAnimatorJPanel object to the JFrame to display the animation.

Fig. 24.4 Animating a ...

Get Java How to Program (early objects), 9/e 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.