Hi there.
When adding images, I have to use the full path to the image rather than just the image file name. The image file is in the same directory as the xcode java project and I have added it to the project. Example:
ImageIcon icon=new ImageIcon("mobilebg.png"); //mobilebg.png is the name of my image file i want to set as a background to my JFrame.
The above does not work when using just the file name. The image does not show.
ImageIcon icon=new ImageIcon("/Users/mfos/Documents/Uni/Java/projects/Mobile/mobilebg.png");
The above does work when I specify the full path to the image. The image shows.
Is there any way I can change this so I don't have to specify the full path? Compiling in terminal works fine with just the filename specified.
Just starting out in Java using xcode.
Posts already on this subject have not helped me.
Many Thanks Mike |