Java Swing ImageIcon, where to put images?

Julie Mariah Christine picture Julie Mariah Christine · Jul 28, 2013 · Viewed 39.3k times · Source

I'm following this tutorial for java swing games: http://zetcode.com/tutorials/javagamestutorial/movingsprites/

At this point:

ImageIcon ii = new ImageIcon(this.getClass().getResource());
image = ii.getImage();

I just don't know what kind of path I have to write and where should I save my images (which directory).

Would you help me please? Would you give an example?

Answer

Steven picture Steven · Jul 28, 2013

In your src folder, create a folder called "images" or "files" then put the image in there.

Then use this:

ImageIcon(this.getClass().getResource("/images/filename.png"));

If that doesn't work, try this:

ImageIcon(this.getClass().getResource("images/filename.png"));