O'Reilly logo

Graphic Java™ 1.2, Volume I: AWT, Third Edition by David M. Geary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Waiting for an Image to Load

Both the applet and application presented so far load and display their images in chunks, from the top of the image to the bottom, due to the asynchronous nature of image loading. A more aesthetically pleasing approach is to wait for the image to load completely before displaying it. There are a number of ways to accomplish this approach; one way is to implement imageUpdate(), which keeps us informed as to the progress of the loading of the image in question.

The applet in Example 5-4 is almost exactly like the one in Example 5-1, except that it implements ImageObserver.imageUpdate().

Example 5-4. An Applet that Waits for An Image to Fully Load
 import java.applet.Applet; import java.awt.Graphics; import java.awt.Image; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required