FaqJ2MEConfigRes
How do I specify resource files (images, sounds) to be added to the JAR build?
Goal: Resources include things like images, sound files, property files. The target JAR file should have all the resources in "res" folder.
Solution: For instance you would like to use specific resources for Nokia Series 40, 60 and Motorola M1. Create following directory structure:
\res\Nokia60
\res\Nokia40
\res\MotorolaM1
Put resource files in specific folders, i. e.
\res\Nokia60\logo.png
\res\Nokia40\logo.png
\res\MotorolaM1\logo.png
Then open project customizer (right click on the Project > Properties) and add the directory with resources in Libraries & Resources (Add Folder). All content of the folder gets added into the JAR file. You may use different folders in different configurations.
Then reference the resources:
ImageIcon logoN60 = new ImageIcon(this.getClass().getResource("res/Nokia60/logo.ping"));
NOTE: getResource() returns a URL path to the location of the resource within the JAR, which can then be passed to ImageIcon or some other method that will use the URL. The path to the file is relative to the class in which this code resides.