FileDocCategorySizeDatePackage
DemoImages.javaAPI DocExample3381Wed Aug 08 15:13:48 BST 2001None

DemoImages

public class DemoImages extends Component
A cache of all the demo images found in the images directory.

Fields Summary
private String[]
names
private static Hashtable
cache
Constructors Summary
public DemoImages()



      
        cache = new Hashtable(names.length);
        for (int i = 0; i < names.length; i++) {
            cache.put(names[i], getImage(names[i], this));
        }
    
Methods Summary
public static java.awt.ImagegetImage(java.lang.String name, java.awt.Component cmp)

        Image img = null;
        if (cache != null) {
            if ((img = (Image) cache.get(name)) != null) {
                return img;
            }
        }

	URLClassLoader urlLoader = (URLClassLoader)cmp.getClass().getClassLoader();
	URL fileLoc = urlLoader.findResource("images/" + name);
	img = cmp.getToolkit().createImage(fileLoc);

        MediaTracker tracker = new MediaTracker(cmp);
        tracker.addImage(img, 0);
        try {
            tracker.waitForID(0);
            if (tracker.isErrorAny()) {
                System.out.println("Error loading image " + name);
            }
        } catch (Exception ex) { ex.printStackTrace(); }
        return img;