I have nearly finished the Java Desktop application. It runs in my Netbeans IDE 6.8. Previously, I would have the program reference image button icons (.jpg) from an absolute path to a folder that I manually created in the same directory. However, to use the distribution freeware (JSmooth) I can find, there is no way to add manually add separate folders, all code and resources must be in the same .jar file.
If I do not require the images (i.e. try cleaning/building with a dummy url to a website's picture), JSmooth can make a single downloadable icon (with a icon image of my choice), and launch the program from it. This is what I want, since users generally do not like to download a .zip containing .jar and images folder, and then click .jar from within the folder (my current mode of distribution). They want to click one button with the image icon and have everything else load.
There are many forum posts on solutions to this problem. I have tried all of them and cannot seem to make it work, so I'm posting this as a job.
Job Requirements: Please read my current status and the things I have tried (below). I would like to email the .zip file containing complete Netbeans project to the freelance programmer. There is a method (shown below) in the main class (JBooks7App) that the GUI class (JBooks7View) frequently calls to get the imageicon. Please alter the getimage(String unique) method such that it can get the images from the .jar and run properly, and send the code back to me. If you must alter the project properties, or anything beyond just the method, please give me detailed instructions on what to change. I make alterations to the program frequently, so I need to know how to build the final product myself, not just be sent the final distributable form. I will disburse payment when I can successfully create a file in JSmooth that I can send to others, and they can open it with one click.
Current Attempts that I have tried:
I believe I have successfully gotten images into the .jar, the Netbeans project directory shows them in my jar directory (see [login to view URL]). The .jar file is larger than it was before I began putting the images in the src folder before clean/build.
However, I cannot reference them from within my program outside of the IDE.
I have tried many versions of making a method in my main directory that the [login to view URL] can call to get an image by using the String "unique" as an argument for the name.
public static ImageIcon getimage(String unique) throws MalformedURLException, IOException{
String imasuffix=".JPG";String surepath= "/";
//Example to show that program works in dist folder after clean/build when images do not need to be loaded from jar
//URL imageURL = new URL("[login to view URL]");
//Tried this too, did not work. workingfold is set to the current directory when the program launches
//Works when in IDE but gives NullPointerException when used in dist after clean/build
// URL imageURL = new URL("jar:file:"+JBooks7App.workingfold+"[login to view URL]!/"+unique+imasuffix);
//Tried this too. This worked in IDE but NullPointerException in dist
URLClassLoader urlLoader=(URLClassLoader)[login to view URL]();
URL r = [login to view URL]("./"+unique+imasuffix);
ImageIcon image = new ImageIcon(r);
//Tried this too. This worked in IDE but NullPointerException in dist
//ImageIcon image = new ImageIcon([login to view URL](unique+imasuffix));
//This is what I used when I manually added a separate images folder to put in the same directory as the jar
/* ImageIcon image = new ImageIcon(JBooks7App.workingfold+"/images/"+unique+imasuffix);*/
//I also tried many solutions starting with .getClass().getResource(), but it tells me it cannot reference a nonstatic //variable from static context. You can try [login to view URL](), which works in