我的图形在导出 Java 项目时不会显示

我正在处理一个Java项目,它包含图像。但是,当我将 Java 项目导出为可运行的 Jar 文件或仅导出 Jar 文件时,屏幕上不会显示任何图像。它在IDE中使用(日食)工作正常。


我已经尝试了人们发布的所有方法。我也使我的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);


一只名叫tom的猫
浏览 92回答 1
1回答

慕运维8079593

尝试做“图像/自动.png”。我猜是因为这是一个文件路径问题。甚至可能是“../图像/自动.png”
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java