小程序好像找不到资源

Applet cannot seem to find resources

有一个类似的问题(Java Applet Cannot Locate Resources),但是base给我一个错误,并要求我创建一个变量。


我有一个嵌入 HTML 的小程序:

<object type="application/x-java-applet" height="600" width="800">
<param name="code" value="net.me.applet.WindowMain" />
</object>

小程序启动,并尝试更改内容窗格的颜色也有效,所以这意味着 link 和 HTML 可能没有错误。

然后,我 link 像这样编辑我的资产:

ImageIcon left = new ImageIcon(getCodeBase(), "Arrow_Left.png");

PNG 与我的小程序在同一目录中。图片没有显示,所以我假设没有找到资产。我也试过 "/Arrow_Left.png",但没有用。

目录结构是这样的:

/ root directory
index.html
(dir)net
     | me
         | applet
               | WindowMain.class

当我在 Eclipse 中开发小程序时,我用编译单元制作了一个包,并在 src 文件夹中创建了一个名为 "assets" 的文件夹,为了测试目的,我使用 ImageIcon("src/assets/Arrow_Left.png")

I put the PNG in the same dir as my WindowMain.class

然后字符串需要是代码库的相对路径。类似于:

ImageIcon left = new ImageIcon(getCodeBase(), "net/me/applet/Arrow_Left.png");

但一定要听取使用 ImageIO.read(..) 的建议,这样可以提供更好的反馈。