The ImageObserver Interface
It is sometimes said, only half in
jest, that WWW stands for “World Wide Wait”, primarily
because of the amount of time it takes for graphics-heavy pages to
load. Although reading large files off a hard drive can be
time-consuming, most users have trained themselves not to notice the
time it takes; file loading seems to happen instantaneously. However,
this is not the case when files are loaded from a network,
particularly when that network is the Internet. It is not uncommon
for even small images to take several minutes to load. Since Java
loads images in a different thread than the main execution of a
program, a program can do something while the pictures are
downloaded. However, programs don’t get impatient; users do. It
is a good idea to keeps users informed about how much of an image has
been loaded and how much longer they can expect to wait. The
java.awt.image.ImageObserver interface allows you
to monitor the loading process so that you can keep the user informed
and use the image as quickly as possible once it does load.
When discussing getImage( ), I said that the
method returned immediately, before downloading the image.
Downloading begins when you try to display the image or do something
else that forces loading to start (for example, passing the
Image object to the prepareImage( ) method of java.awt.Component). Because loading takes place in a separate thread, programs don’t have to spin their wheels while lots of pictures are downloaded; ...