【问题标题】:image icon not appearing outside eclipse图像图标没有出现在日食之外
【发布时间】:2013-02-17 16:26:33
【问题描述】:

我用图形用户界面制作了一个国际象棋游戏,使用图像作为棋子。它在 eclipse 中运行时完美运行。但是,我尝试导出 jar(来自 eclipse)并在 cmd 中运行它,但没有出现任何图像(但是游戏本身运行良好,我只需要猜测碎片在哪里)。 我将假设图像的地址存在问题... 问题是,我什至无法打开 jar 文件中的任何文件以查看发生了什么。

在eclipse中,所有的图片都在scr文件夹的一个包里,而且肯定在jar里面。

有什么建议吗?

【问题讨论】:

  • 加载图片的代码是什么?
  • 请发帖SSCCE
  • "image= new ImageIcon("src/ChessGraphics/WhiteK.png");"

标签: java image jar icons embedded-resource


【解决方案1】:

如果你想在你的 jar 文件中加载图片,你需要使用 Class.getResource(String) 方法。

有关详细说明,请参阅 Java 教程中的 How to Use Icons 部分。

【讨论】:

  • 谢谢。做到了。我替换了“image=new ImageIcon("src/ChessGraphics/WhiteK.png");" with " image= new ImageIcon(this.getClass().getResource("/ChessGraphics/WhiteK.png"));"
猜你喜欢
  • 1970-01-01
  • 2016-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多