This image shows the file structure of my project:
Jar and HTML file: http://files.herenbdy.com/Game.zip
All the XML files I use are within the config folder, and all images within library. The applet is inside the main package, Main.java.
First problem: I found out that Toolkit.getDefaultToolkit.getImage(String filename) does not work within a jar, and that I need to get the URL of the file. Trying to use the following code from within the BitmapGraphic class:
Expand|Select|Wrap|Line Numbers
- private URL getURL(String filename) {
- URL url = null;
- try {
- url = this.getClass().getResource(filename);
- }
- catch (Exception e) { }
- return url;
- }
- public void loadImg(String filename){
- img = tk.getImage(getURL(filename));
- }
I write image file names as: "../library/units/Mainchar.png" to pass into the loadImg function. Removing the ".." does nothing. What is the proper way to load images from within a JAR file?
Second problem:
Sometimes the java console of my browser displays an error saying that it cannot find the XML file, the filenames I use for xml files is: "../config/maps/test.xml".
Can anyone help? The game is useless if it can only be run within Eclipse ><