正如标题所述,我一直在尝试将图像放入“ JOption消息”对话框中。当它们在eclipse中运行时,我已经显示了它们,但是当我将文件导出到可执行jar中时,图像不会加载。
ImageIcon normal = new ImageIcon("src/project/normal.png");
ImageIcon happy = new ImageIcon("src/project/happy.png");
ImageIcon jackpot = new ImageIcon("src/project/jackpot.png");
ImageIcon fail = new ImageIcon("src/project/fail.png");
ImageIcon error = new ImageIcon("src/project/error.png");
我只是在JOptionPane.showMessageDialogue中调用ImageIcon的名称
您当前正在从文件中读取图像,并将其导出到可执行jar中时,该文件不再可用。相反,请尝试将图像作为资源:
ImageIcon imageIcon = new ImageIcon(getClass().getResource("/image.png"));