获取图片的方法
//获取图片
public static Image readImage(String path)
{
Image image = null;
try
{
//返回当前运行文件的目录
InputStream resourceAsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
image = ImageIO.read(resourceAsStream);
resourceAsStream.close();
}
catch (IOException e)
{
e.printStackTrace();
}
return image;
}
运用该方法找到图片
//背景图
public static Image bgImg = readImage("imgs/bg.jpg");