前情提要
学校要交一个拼图游戏的练习项目。
运行良好,发现导入jar以后运行看不到图片。
之前的代码为:
String resource = "image/01.jpg";
Jlabel image = new Jlabel(new ImageIcon(resource));
之后的代码:
String resource = "image/01.jpg";
URL url = getClass().getResource(resource);
Icon icon = new ImageIcon(url);
Jlabel image = new Jlabel();
iamge.setIcon(icon);