【发布时间】:2011-02-05 18:03:03
【问题描述】:
我正在尝试在运行 JApplet 时从 JAR 文件加载 PNG 图像。 我认为该文件已正确加载-没有错误。 但是它不显示。 img.png 与 MainClass.java 文件放在同一目录中。 代码如下:
InputStream imageURL = this.getClass().getResourceAsStream("img.png" );
byte[] bytes = null;
try {
bytes = new byte[imageURL.available()];
System.out.println(imageURL.available());
imageURL.read(bytes);
}
catch(Exception e) {System.out.println("bleah");}
Image image = Toolkit.getDefaultToolkit().createImage(bytes);
Image imageScaled = image.getScaledInstance( 100, 150, Image.SCALE_SMOOTH );
jLabel6 = new javax.swing.JLabel( new ImageIcon( imageScaled) );`
和 HTML 摘录:
<APPLET codebase="classes" code="myapplet/MainClass.class" archive ="LittleApplet.jar" width=700 height=500></APPLET>
正如我所写,图像可能已被读取,但未显示在 JLabel 中。
我错过了什么/做错了什么?
提前感谢您的回复!
【问题讨论】: