java基础-eclipse图片路径问题
1.把新建的文件夹设置为Source Folder
2.现在可以把你刚刚设置的文件夹直接当做是在java项目的src目录下进行操作了
例如设置图标:
①绝对路劲
this.setIconImage(new ImageIcon(“E:\GoogleDownload\Source\Bullet.png”).getImage());
②相对路径
this.setIconImage(new ImageIcon(this.getClass().getResource("/photos/shuttle.png")).getImage());
③利用流-这里也采用的是相对路径
BufferedImage image = ImageIO.read(this.getClass().getResource("/photos/shuttle.png"));
this.setIconImage(image);