import java.awt.*;
import java.net.*;

public class ImageLoader
{
    
    public static Image loadImage(Component comp, URL theSource)
    {
	Image im;
	MediaTracker tracker = new MediaTracker(comp);
	im = comp.getToolkit().getImage(theSource);
	tracker.addImage(im,0);
    
	// wait for image to load
    
	try   { tracker.waitForID(0); }
	catch (InterruptedException e){
	    System.err.println("image loading interrupted");
	    return null;
	}
	if (tracker.isErrorID(0))
	{
	    System.err.println("problem after loading"+theSource.getFile());
	}
	return im;
    }

    public static Image loadImage(Component comp, String filename)
    {
	URL source = null;
	try{
	    source = new URL("file:"+filename);	    
	}
	catch (MalformedURLException e)
	{
	    System.err.println(e);
	}
	return loadImage(comp,source);
    }
}
