The java.awt.MediaTracker class is a useful class.It can monitor the progress of any number of images, so you can expect to all images are loaded or to be loaded only specific. Furthermore, can check for errors. The constructor is: public MediaTracker (Component comp) This constructor creates a new MediaTracker for pictures to be displayed in the variable comp, but really this parameter is not particularly important.
To upload images, a MediaTracker object provides the method following :
public void addImage ( Image image , int id)
This method adds the thumbnail image to the image list to load the object MediaTracker receiving the message . The id variable is used as the number of image identification when using other methods concerning this class.
import java.awt.*;
import java.applet.*;
public class JavaExampleMediaTrackerInJavaApplet extends Applet
{
Image Img;
public void init()
{
MediaTracker Trckr = new MediaTracker(this);
Img = getImage(getDocumentBase(),"Koala.jpg");
Trckr.addImage(Img,0);
try
{
Trckr.waitForAll();
}
catch (InterruptedException e1) { }
}
public void paint(Graphics gr)
{
gr.drawImage(Img, 10, 10, this);
}
}
/*<APPLET CODE=JavaExampleMediaTrackerInJavaApplet.class WIDTH=600 HEIGHT=150> </APPLET>*/