Java Swing ImageIcon, where to put images?

embedded-resource, imageicon, java, packaging, swing

Solution

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"));

Problem

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?

Original source

Related problems