Loading Images
One of the challenges in building software for networked
applications is that data is not always instantly available. Since some of
Java’s roots are in Internet applications such as web browsers, its image
handling APIs were designed specifically to accommodate the fact that
images might take some time to load over a slow network, providing for
detailed information about image-loading progress. While many client
applications do not require handling of image data in this way, it’s still
useful to understand this mechanism if for no other reason than it appears
in the most basic image-related APIs. The Swing toolkit adds its own layer
of image handling over this with components such as ImageIcon, which encapsulates an image source
for you. After reading this chapter, you’ll have an understanding of how
the layers fit together.
ImageObserver
In the previous chapter, we mentioned that all operations
on image data (e.g., loading, drawing, scaling) allow you to specify an
“image observer” object as a participant. An image observer implements
the ImageObserver interface, allowing it to receive notification as information about the image becomes available. The image observer is essentially a callback that is notified progressively as the image is loaded. For a static image, such as a GIF or JPEG data file, the observer is notified as chunks of image data arrive and also when the entire image is complete. For a video source or animation (e.g., GIF89), the image observer is ...