【发布时间】:2017-11-20 21:01:29
【问题描述】:
所以我正在使用 Java 制作一个基本的文本冒险游戏,我决定包含图像。 我用来将图像加载到程序中的代码是这样的:
imagePanel = new JPanel();
imagePanel.setBounds(50, 50, 400, 260);
imagePanel.setBackground(Color.BLACK);
con.add(imagePanel);
imageLabel = new JLabel();
image = new ImageIcon(".//res//towngate.jpg");
imageLabel.setIcon(image);
imagePanel.add(imageLabel);
当我在 Eclipse 中运行该程序时,一切正常,但是当我将其导出为 jar 时,没有图像出现。 如果有人能帮我解决这个问题,我将不胜感激。谢谢!
【问题讨论】:
-
jar 中的对象不是文件,因此您不能使用 ImageIcon 构造函数的文件名形式来访问它们。看到类似this question