| MediaTracker |
| Last modified on January 24, 2002 by rpj@cs.rit.edu. | ||
| MediaTracker |
| MediaTracker lets you wait | |
for images to finish
loading before proceeding with the program. The constructor takes one
argument (a java.awt.component), and so is typically invoked as:
MediaTracker tracker = new MediaTracker(this); |
| Last modified on January 24, 2002 by rpj@cs.rit.edu. | ||
| MediaTracker |
| MediaTracker lets you wait |
| You can register operations with a MediaTracker object | |
For example,
Image picture = toolkit.getImage("filename.jpg");
tracker.addImage(picture,7);
The "7" is an ID number that we associate with this image loading
operation. Images of lower ID are loaded first. The MediaTracker can
wait for all images of the same ID to finish loading. |
| Last modified on January 24, 2002 by rpj@cs.rit.edu. | ||
| MediaTracker |
| MediaTracker lets you wait |
| You can register operations with a MediaTracker object |
| To wait for all images to finish loading | |
try {tracker.waitForAll();}
catch (InterruptedException ex) {}
Similarly, you can wait for all processes that have a given ID, say 42, using
waitForID(42) |
| Last modified on January 24, 2002 by rpj@cs.rit.edu. | ||
| MediaTracker |
| MediaTracker lets you wait |
| You can register operations with a MediaTracker object |
| To wait for all images to finish loading |
| Or you can check the status of the load | |
while (tracker.statusID(1,true) != MediaTracker.COMPLETE) {
//wait for it
}
|
| Last modified on January 24, 2002 by rpj@cs.rit.edu. | ||
| MediaTracker |
| MediaTracker lets you wait |
| You can register operations with a MediaTracker object |
| To wait for all images to finish loading |
| Or you can check the status of the load |
| A program to load and display an image | |
| the program |
| Last modified on January 24, 2002 by rpj@cs.rit.edu. | ||
| MediaTracker |
| MediaTracker lets you wait |
| You can register operations with a MediaTracker object |
| To wait for all images to finish loading |
| Or you can check the status of the load |
| A program to load and display an image |
| Similar program | |
| There is a similar program in the text book, on page 166. Note that it does not use a MediaTracker. But it does use a dialog box to select the file instead of doing it via command-line arguments. |
| Last modified on January 24, 2002 by rpj@cs.rit.edu. | ||
| MediaTracker |
| MediaTracker lets you wait |
| You can register operations with a MediaTracker object |
| To wait for all images to finish loading |
| Or you can check the status of the load |
| A program to load and display an image |
| Similar program |
| Busywait or Sleep? | |
| Should the program do anything useful while it is waiting for the file to load? Discuss. |
| Last modified on January 24, 2002 by rpj@cs.rit.edu. | ||