Image Icon help

Hello, I am trying to run a basic clicker game for school using github pages. Im using java8 and running cheerpj with a basic html file. The game loads and all the buttons and labels work. But none of the images I had set load. I put the images in the same folder as the source files and that still didn't work. My IDE runs the code just fine, heres link to the game https://wethan006.github.io/. If you have any ideas let me know what you need from me (screenshots or source code)
9 Replies
apignotti
apignotti3mo ago
Hi, welcome to the community. You mention the images are in the same directory as the jars, usually this means they are loaded from the "current directory" (cwd)
Dexials
DexialsOP3mo ago
quick up date I am adding the extends applet tag and am going to try it that way real quick to see if it make a difference
apignotti
apignotti3mo ago
cwd in CheerpJ is /files, while your jar file is over HTTP /app Currently CheerpJ does not support setting a custom cwd. Your best option if you can change the source code is to explicitly use /app for your resources or make the root folder configurable with a command line option or java property I am not sure what you mean by "extends applet tag" here, so I can't provide any feedback
Dexials
DexialsOP3mo ago
no worries it didnt work I just reverted back to what I had so are saying that for the image path I need to add /app or that I need to add a /app folder that will also contain the images?
apignotti
apignotti3mo ago
You need to prefix /app to your resources, they will then be loaded over HTTP, like your jars
apignotti
apignotti3mo ago
For more information about how the filesystem works in CheerpJ: https://cheerpj.com/docs/guides/File-System-support
Leaning Technologies Developer Hub
Files and filesystems - CheerpJ Documentation
Virtual filesystems and how to use them
Dexials
DexialsOP3mo ago
Thank I'll read up on this and try some things, seem what happens Alright you were on to something. I needed to upload my image folder into the git repository and change the image path in my source code to reflect this. like "/app/folder/image.jpg". Now the only issue is github seems to not like uploading images and I literally have to slowing add them one at a time. But it is working
apignotti
apignotti3mo ago
Another technique you could consider is to store images directly in JAR files. This is not a CheerpJ-specific approach, but an official Java feature. I'll consider the issue closed on our side
Dexials
DexialsOP3mo ago
Thank you that actually what I did the first time. I have the image folder and image in the jar file

Did you find this page helpful?