Image i = createImage( (java.awt.image.ImageProducer) url.getContent() ); MediaTracker mediaTracker = new MediaTracker(this); mediaTracker.addImage(i,1);
But I would like to put the images in the img directory and not in the classes directory. Is there any way to do it? I was thinking about a properties file specifying the image place as hard code (for instance, C:\Project\application_name\img) but I do not if that�s a good idea. Can anyone help me?
If the img folder is in your classpath then you should be able to load the images it contains with: java.net.URL url = getClass().getResource("img/" + image_name); You shouldn't have to specify where the img folder is relative to the classes folder. The class loader does that for you.
Joined: Mar 26, 2007
Hi Craig. Thank you for your help.
I've found another way for not use getClass().getResource(image_name).
That�s: File file = new File("img/" + image_name); Image i = ImageIO.read(file);