1) getClass().getResource("info.png") already returns a URL. I think that if you print getClass().getResource("info.png") and new java.net.URL(getClass().getResource("info.png"), "info.png") you would see that they are the same.
2) the resource paths are by default relative to the current class. However, that doesn't mean you're constrained to resources in the same folder. You can use resources in a folder (package) inside your current package, by adding a directory part to the resource name: "images/info.png". You can use .. to go one level down: "../info.png". And if your resource starts with a / it will be absolute: "/com/coderanch/pkg/info.png".
Is images a sub folder of the folder where your class file is located?
Joined: Apr 28, 2010
I have folder named classes (project made in NetBeans) and in it folders impl and images (folders of packages). Folder impl has class files and images. I would like to place images in folder (package) images and to call it from there.