I am writing a Java Applet. I am using images to display content on the Applet window. I have a separate folder in which all of these images are contained. This folder is not in the src or bin folder but a separate folder. This folder is called 'assets'. Inside this folder, there is a folder called 'images'. Inside this asset folder, I have a couple sub folders. In these sub folders, I have the images I am using. I use the methods listed below to load these images and display them onto the screen. The Applet runs fine in Eclipse. The problem occurs when I try putting the Applet onto a website. I have done quite a bit of searching, but of the things I tried, none of them solved my problem. I scan an image for certain pixel colors. My code I am using for the images is listed below. When I look at my .jar file, my images seem to be in the .jar file. (I used the Unarchived and JD-GUI to view the .jar file) Please let me know what I should do.
~Rane
Method for drawing image onto the screen:
loadImg.renderImage("images/walls/lawn.png", xCoord, yCoord, imgWidth, imgHeight, graphics);
renderImage method:
public void renderImage(String path, int x, int y, int width, int height,
Graphics g) {
g.setColor(Color.BLACK);
g.fillRect(x, y, width, height);
g.drawImage(getImage(path), x, y, width, height, applet);
}
getImage method:
public Image getImage(String path) {
Image img;
URL url = null;
try {
url = applet.getDocumentBase();
} catch (Exception e) {
// TODO: handle exception
}
img = applet.getImage(url, path);
return img;
}
My HTML:
<object type="application/x-java-applet" archive="Applet.jar" code="AppletGame.class" width="600" height="600"></object>
Two of the many answered that DIDN'T work for me: