Like this:
img = Toolkit.getDefaultToolkit().getImage("image.gif");
and:
codeBase = new URL("file:" + System.getProperty("user.dir") + "/");
soundURL = new URL(codeBase,"sound.wav");
theSound = Applet.newAudioClip(soundURL);
I think thats the problem. The method getImage("image.gif") access the image from the filesystem and so won't check the jar. If you use
1 2
| url = YourClass.class.getClassLoader().getResource("image.gif"); img = Toolkit.getDefaultToolkit().getImage(url); |
Where "YourClass" is the class name of the current class that should work. Likewise for the sounds:
1 2
| url = YourClass.class.getClassLoader().getResource("sound.wav"); theSound = Applet.newAudioClip(url); |
Both of these access the resources via the class path, so if the jar is in the classpath it should work. Infact you can then put the resources wherever you like in the classpath (maybe another jar?).
Hope it helps,
Kev