在普通小程序中,我使用它来将图像加载到 JLabels
Image back2 = getImage(getDocumentBase(), "images/blank_blue.png");
ImageIcon background2Icon = new ImageIcon(back2);
JLabel pic2 = new JLabel(background2Icon);
当我尝试使用 Java Web Start 小程序执行此操作时,什么也没有出现。在 Java 控制台中,它说 this
basic: Loaded image: file:/C:/Users/jdfksl/Desktop/webStartTest/images/blank_blue.png
并且没有错误,但它不会出现。
我以这种方式在 Java Web Start 中工作的 JLabels 中加载了图像
BufferedImage image=null;
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
image = ImageIO.read(classLoader.getResourceAsStream("images/ghast_skin.png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
但是,我想要一种更短的加载图像的方式。还有其他选择吗?
这是我的 jnlp 文件内容
<?xml version="1.0" encoding="UTF-8"?>
<jnlp href="jws_tester.jnlp">
<information>
<title>JWS tester</title>
<vendor>HTZ.</vendor>
<description>Testing with JWS</description>
<offline-allowed />
</information>
<resources>
<j2se version="1.4+"
href="http://java.sun.com/products/autodl/j2se" />
<jar href="tester.jar" main="true" />
<!-- Specify if using JNLP extensions
<extension name="SomeExtension"
href="http://some.server.com/some_extension.jnlp" />
-->
</resources>
<security>
<all-permissions/>
</security>
<applet-desc
name="JWS tester"
main-class="mather.Main"
width="900"
height="600">
</applet-desc>
</jnlp>