ImageObserver is a Java interface for tracking the loading of images.
The ImageObserver
provides:
An asynchronous update interface for receiving notifications about Image information as the Image is constructed.
The AWT class Toolkit
provides many methods for loading and creating images, and most of them work asynchronously (the code continues on, while the image is loaded in the background).
Image loading can be tracked using a MediaTracker
, but any class that implements an ImageObserver
effectively takes over any steps necessary in updating the component or view as more of the image is loaded. The Swing based JComponent
(parent of all other Swing components except top level containers) implements ImageObserver
.
To leverage the power of the observer in custom painting, an image might be drawn to the Graphics
instance using:
// Where 'this' implements ImageObserver
graphics.drawImage(img,0,0,this);