Java The Complete Reference, Seventh Edition

(Greg DeLong) #1

Chapter 25: Images 765


This example creates a newMediaTrackerin theinit( )method and then adds each of the
named images as a tracked image withaddImage( ).Inthepaint( )method, it callscheckID( )
on each of the images that we’re tracking. If all of the images are loaded, they are displayed.
If not, a simple bar chart of the number of images loaded is shown, with the names of the
fully loaded images displayed underneath the bar. Figure 25-3 shows two scenes from this
applet running. One is the bar chart, displaying that three of the images have been loaded.
The other is the Van Gogh self-portrait during the slide show.

ImageProducer


ImageProduceris an interface for objects that want to produce data for images. An object that
implements theImageProducerinterface will supply integer or byte arrays that represent
image data and produceImageobjects. As you saw earlier, one form of thecreateImage( )
method takes anImageProducerobject as its argument. There are two image producers
contained injava.awt.image:MemoryImageSourceandFilteredImageSource. Here, we
will examineMemoryImageSourceand create a newImageobject from data generated in
an applet.

FIGURE 25-3

Sample
output from
TrackedImageLoad
Free download pdf