我正在开发一个 Java 项目,它包含图像。但是,当我将 Java 项目导出为可运行 Jar 文件或只是 Jar 文件时,屏幕上不会出现任何图像。它在我使用的 IDE(Eclipse)中运行良好。
我已经尝试了人们发布的所有方法。我也将我的 res 文件夹作为主文件夹。
newFrame.setTitle("Mustache Clicker");
jLabel1.setText(i + "");
URL mustache1 = mainscreen.class.getResource("/images/mustache.png");
ImageIcon mustache = new ImageIcon(mustache1);
URL mustache2 = mainscreen.class.getResource("/images/Mustache Mine.png");
ImageIcon miner = new ImageIcon(mustache2);
URL mustache3 = mainscreen.class.getResource("/images/Auto .png");
ImageIcon auto = new ImageIcon(mustache3);
URL mustache4 = mainscreen.class.getResource("/images/mustache (1).png");
ImageIcon rain = new ImageIcon(mustache4);
URL mustache5 = mainscreen.class.getResource("/images/city.png");
ImageIcon city = new ImageIcon(mustache5);
jButton2.setIcon(miner);
jButton1.setIcon(mustache);
jButton3.setIcon(auto);
jButton4.setIcon(rain);
jButton5.setIcon(city);
最佳答案
尝试执行“images/Auto.png”。我猜是因为这是一个文件路径问题。 甚至可能是“../images/Auto.png”
关于java - 当我导出 Java 项目时,我的图形不会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55458068/