What is the best way to load images and XML data to a java applet?
What I have at the moment is an Slick2D Game applet. I have a content loader from an application project that takes an XML file containing links to the games separate image/sound/particles, etc that need to be loaded.
Finally I have a directory called ‘art’ that contains the actual image files.
On my server I have kept the same directory structure as the application version:
MyApplet
- data
- resources.xml
- art
- image1.png
- image2.png
- image3.png
- image4.png
When running the applet, I get the following error:
Exception in thread "Thread-14" java.lang.ExceptionInInitializerError
at DecoGame_NixieClock.NixieClockGame.init(NixieClockGame.java:43)
at org.newdawn.slick.AppletGameContainer$Container.initApplet(AppletGameContainer.java:272)
at org.newdawn.slick.AppletGameContainer$ContainerPanel.initGL(AppletGameContainer.java:229)
at org.newdawn.slick.AppletGameContainer$ContainerPanel.start(AppletGameContainer.java:216)
at org.newdawn.slick.AppletGameContainer$1.run(AppletGameContainer.java:92)
Caused by: java.security.AccessControlException: access denied (java.io.FilePermission data\resources.xml read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at Content.ResourceManager.<init>(ResourceManager.java:50)
at Content.ResourceManager.<clinit>(ResourceManager.java:33)
... 5 more
If I’m right, this is because applets are not allowed to access the local file-system.
Is there a method for loading data to an applet from the server?
This is the layout of the XML file I use to store my content links:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<!-- GAMEPLAY -->
<!-- GUI -->
<resource type="image" id="IMAGE_1">art\image1.png</resource>
<resource type="image" id="IMAGE_2">art\image2.png</resource>
<resource type="image" id="IMAGE_3">art\image3.png</resource>
</resources>
Would it just be a matter of changing these links to say ‘www.mydomain.com/applet/art/image1.png’ or is there a better way?