Jump to content
  • Advertisement
Sign in to follow this  

[java] Java Applet + loading data?

This topic is 4542 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently working on a game that's running as Java applet. Right now, I don't use any graphics yet, but in the future, the game has to load a bunch of bitmaps and definition files. I don't like the idea of shoving these into the JAR, because updating the graphics/definition files would mean re-creating the JAR file. The guy for who I'm building this misses the knowledge to do this, and writing a document for it means that I'm constantly supporting him because he doesn't know how to do it. So, I was thinking: Can I use a zip file, and download that from within the applet, open it, load the images, etc.? Toolmaker

Share this post

Link to post
Share on other sites
In a java applet you can load any external resource with a url, Including resources packed within .jar or .zip files.

in the URL instantiation you can specify the location.

Resource in a Jar file:

Resource in a Zip file:

So basically the only thing that changed between the two is whether the arhive ends with .jar or .zip because their basically the same file types only a jar file can contain the META-INF folder which java uses to execute jar files.

To load an external image using is just create the URL object like so:

URL externalImage = new URL(jar:http://<mydomain>/<myarchive>.zip!/images/mgimage.gif);

Then use that as the arguement to an ImageIcon or however you want to load the image.

Image background = (new ImageIcon( new URL("jar:http://fairmi73.tripod.com/PunchOut/Test/PunchOut.zip!/stage.gif") ) ).getImage();

Hope that helps!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!