标签:
public class GameUtil{
public static Image getImage(String path){
URL u=GameUtil.class.getClassLoader().getResource(path);
System.out.println(u);
BufferedImage img=null;
try {
img=ImageIO.read(u);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return img;
}
}
然后直接使用该静态方法即可
如Image img=GameUtil.getImage("Images/3.jpg");
标签:
原文地址:http://www.cnblogs.com/WuDG/p/5927500.html