Java Swing ImageIcon, where to put images?

后端 未结 3 1655
小蘑菇
小蘑菇 2020-12-03 22:37

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

At this point:

ImageIcon ii = new Im         


        
3条回答
  •  不思量自难忘°
    2020-12-03 22:55

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

提交回复
热议问题