Skip to Content
Java Network Programming, Second Edition
book

Java Network Programming, Second Edition

by Elliotte Rusty Harold
August 2000
Intermediate to advanced
760 pages
21h
English
O'Reilly Media, Inc.
Content preview from Java Network Programming, Second Edition

The MediaTracker Class

The ImageObserver interface is useful for monitoring a single image, but it starts to fall apart when faced with multiple images. The java.awt.MediaTracker class can track the loading status of many different images and organize them into logical groups. In future versions of Java, it may even be able to monitor the loading of audio clips and other kinds of multimedia content. However, Sun’s been promising this since Java 1.0 and still hasn’t delivered, so I’m not holding my breath.

To use java.awt.MediaTracker, simply create an instance of MediaTracker and then use the MediaTracker’s addImage( ) method to place each Image you care about under the MediaTracker’s control. When you add an Image to a MediaTracker, you give it a numeric ID. This ID does not have to be unique; it is really a group ID that is used to organize different images into groups. Before using the image, you call a method such as checkID( ) to see whether the image is ready. Other methods let you force loading to start, discover which images in a group have failed to load successfully, wait for images to finish loading, and so on.

Note

One difference between a MediaTracker and an ImageObserver is that the MediaTracker is called before the Image is used, while an ImageObserver is called after the Image is used.

Example 9.7 is an applet that loads an image from the Net. As usual, the image is loaded from the document base, and the name of the image file is read from a <PARAM> tag; the name ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Network Programming, 4th Edition

Java Network Programming, 4th Edition

Elliotte Rusty Harold
Java Concurrency, 2/e

Java Concurrency, 2/e

Douglas Schmidt

Publisher Resources

ISBN: 1565928709Supplemental ContentCatalog PageErrata