FileDocCategorySizeDatePackage
trackImage.javaAPI DocExample798Thu Apr 03 15:22:32 BST 1997None

trackImage.java

import java.awt.*;
import java.applet.*;

public class trackImage extends Applet implements Runnable {

  Thread play;
  Image thePicture;
  MediaTracker theTracker;

  public void init() {

    thePicture = getImage(getDocumentBase(), getParameter("imagefile"));
    theTracker = new MediaTracker(this);
    theTracker.addImage(thePicture, 1);
       
    play = new Thread(this);
    play.start();
  
  }
  
  public void run() {
  
    try {
      theTracker.waitForID(1);
      repaint();
    }
    catch (InterruptedException ie) {      
    }
  
  }
  
  public void paint(Graphics g) {
   
    if (theTracker.checkID(1, true)) {
      g.drawImage(thePicture, 0, 0, this);
      play.stop();
    }
    else {
      g.drawString("Loading Picture. Please hang on", 25, 50);
    }
    
  }
  
}