import java.awt.*; import java.applet.*; import java.net.*; /** get an Image file from the jar or the codebase or the docuementbase */ public class GetImageFile { Applet mom; boolean fromJar; public GetImageFile(Applet parent) { mom = parent; fromJar = false; } public URL getFile(String name) { URL u = getClass().getResource( (String) name); if (u == null) { fromJar = false; u = mom.getDocumentBase(); } return u; } public Image getImage(String name) { // first try the URL Image img = null; URL u = getClass().getResource( (String) name); if (u == null) { fromJar = false; u = mom.getDocumentBase(); img = mom.getImage(u,name); } else { fromJar = true; img = mom.getImage(u); } MediaTracker mt = new MediaTracker(mom); mt.addImage(img, 0); try { mt.waitForAll(); } catch ( Exception ex ) {img = null; } return img; } public AudioClip getAudioClip(String name) { // first try the URL AudioClip auc = null; URL u = getClass().getResource( (String) name); if (u == null) { fromJar = false; u = mom.getDocumentBase(); auc = mom.getAudioClip(u,name); } else { fromJar = true; auc = mom.getAudioClip(u); } return auc; } public boolean wasLastLoadFromJAR() { return fromJar; } }