by Dinesh Thakur

When the images are initially loaded, they are only partially displayed as they may not have been loaded completely. Mediatracker tracks the status of the number of media objects which includes audio clips as well as images. Secondly, it also determines if an image has been completely loaded.

To use a media tracker, create an instance of MediaTracker and call its addImage method for each image to be tracked. In addition, each image can be assigned a unique identifier. This identifier controls the priority order in which the images are fetched. It can also be used to identify unique subsets of the images that can be waited on independently. Images with a lower ID are loaded in preference to those with a higher ID number.

          import java.applet.Applet;

          import java.awt.*;
          import java.awt.event.*;
          /* <APPLET CODE=MediaTrackerClass.class WIDTH=400 HEIGHT=200 > </APPLET> */
          public class MediaTrackerClass  extends Applet implements AdjustmentListener
              {
                    Image image;
                   Scrollbar horiz=new Scrollbar(Scrollbar.HORIZONTAL,0,400,0,500);
                   Scrollbar vert=new Scrollbar(Scrollbar.VERTICAL,0,400,0,500);
                   public void init()
                    {
                   setLayout(new BorderLayout());
                   loadImage();
                  add(vert,BorderLayout.EAST);
                  add(horiz,BorderLayout.SOUTH);
                  horiz.addAdjustmentListener(this);
                  vert.addAdjustmentListener(this);
               }
                      void loadImage()
                        {
                          Toolkit toolkit=getToolkit();
                      image=toolkit.getImage("DineshThakur.gif");
                      MediaTracker tracker=new MediaTracker(this);
                      tracker.addImage(image,7);
                         try
                        {
                               tracker.waitForID(7);
                        }
                                   catch(InterruptedException ex)
                                 {
                                 }
                    }
                                  public void paint(Graphics g)
                                    {
                                      g.drawImage(image,0-horiz.getValue(),0-vert.getValue(),this);
                            }
                                      public void adjustmentValueChanged(AdjustmentEvent e)
                                {
                                   repaint();
                                }
           }   

MediaTracker Class in java Example