Paths inside Jars are paths, not actual directories, as you can use them on the file system. To get all resources in a specific Jar file path:
- Type the
URL pointing to the Jar. - Get
InputStream from URL . - Build a
ZipInputStream from InputStream . - Iterate
ZipEntry each ZipEntry , looking for matches with the desired path.
.. can I still check my applet when it is not inside this jar? Or will I have to program two ways to get my images?
ZipInputStream will not work with free resources in file system directories. But then I highly recommend using a build tool such as Ant to build (compile / gang / character, etc.) the applet. It may take an hour or so to write the script assembly and test it, but after that you can create the project with a few keystrokes and a few seconds.
It would be very unpleasant if I always had to extract and sign my jar, if I want to check my Aplet
I'm not sure what you mean. Where does the “extract" come from? In case I was not clear, the sandbox applet can load resources this way from any Jar that is mentioned in the archive attribute. Another thing you can do is separate the Jar (s) resources from the Jar applet. Resources usually change less than code, so your assembly may have several shortcuts.
I think I really need to consider placing my images in a separate directory outside the bank.
If you mean on the server, there will be no practical way to get a listing of image files without the help of the server. EG. Some servers are unstable for creating an “HTML-based file list” for any directory without a default file (for example, index.html).
I have only one bank in which my classes, images and sounds.
OK - consider moving sounds and images to a separate jar. Or at least put them in a jar without compression. While Zip's collection methods work well with classes, they are less efficient at compressing (otherwise already compressed) media formats.
I need to sign it because I use the Preferences class to save user preferences. "
There are alternatives to Preferences for applets, such as cookies. In the case of an applet with plugin 2, you can launch the applet (still built into the browser) using Java Web Start . JWS offers a PersistenceService. Here is my little demonstration . PersistenceService services .
Speaking of JWS, this brings me to: are you absolutely sure that this game will be better than an applet and not an application (for example, using JFrame ) launched using JWS?
Applets will not give you any stress, and JWS has offered PersistenceService since its introduction in Java 1.2.