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;