import java.awt.*;

// This appears in Core Web Programming from
// Prentice Hall Publishers, and may be freely used
// or adapted. 1997 Marty Hall, hall@apl.jhu.edu.

/** A utility class that lets you load and wait
 *  for an image or images in one fell swoop.
 *  If you are loading multiple images, only
 *  use multiple calls to waitForImage if you
 *  <B>need</B> loading to be done serially.
 *  Otherwise use waitForImages, which loads
 *  concurrently, which can be much faster.
 */

public class TrackerUtil {
  public static boolean waitForImage(Image image,
                                     Component c) {
    MediaTracker tracker = new MediaTracker(c);
    tracker.addImage(image, 0);
    try {
      tracker.waitForAll();
    } catch(InterruptedException ie) {}
    if (tracker.isErrorAny())
      return(false);
    else
      return(true);
  }

  public static boolean waitForImages(Image[] images,
                                      Component c) {
    MediaTracker tracker = new MediaTracker(c);
    for(int i=0; i<images.length; i++)
      tracker.addImage(images[i], 0);
    try {
      tracker.waitForAll();
    } catch(InterruptedException ie) {}
    if (tracker.isErrorAny())
      return(false);
    else
      return(true);
  }
}

