Paths And Such
Currently working on making a chess application, and I'm using images and sounds too, but...
Whenever I transfer my project to my laptop I have to reconfigre the path my images and songs-.-"
Can anyone explain/show me to add images to a jar file or a package or something so that the program automatically finds the files for me?
Package the resource files into your jar or somewhere relative to your bin files, then use Class.getResource() to get the URL to the file (linux/unix like paths where a starting '/' is the root of the jar, and without the starting slash is relative to the calling class) - you can then use something like ImageIO.read to load the image
Could you please show me how to do that, or direct me to a website?
Originally Posted by doWhile
Thanks a lot!
EDIT: I'm using netbeans
It all depends upon how you are creating your project, so no. Instead, I recommend you try google or search these forums based upon the advice I gave you above
Netbeans jars things up automatically.
You just need to have an images (or resources, or whatever you want to call it) directory under your src directory and plonk them all in there. Then use the jar that it dumps in the dist directory.
Ok, so I have my pictures in this package...
How do I use them in my code?:confused:
Get them as an Image (preferably), or an ImageIcon
So they're now in your chess.jar, because Netbeans will do this on a build.
You will refer to them as getResourceAsStream, usually.
The location will be /chess/Pics/filename.
ETA; The resulting stream can then be used instead of a file. Not knowing how you are doing it currently I can't say how to change it.