我有一个加载一系列图标的类,我的小程序使用 2 个这样的数组,一个用于图像,一个用于缩略图。 我有一个动画线程,它通过缩略图数组旋转一组 6 个缩略图,以及一个允许滚动缩略图的 slider 。
当我使用小程序查看器时,程序工作正常,但如果我打包小程序并在浏览器上查看它,或者如果我将未打包的小程序上传到网站上,则缩略图,但不是使用相同类加载的图像不会显示在屏幕上,并且缩略图附带的功能变得迟缓。
我不能保证该网站不会改变,但您可以尝试亲自查看错误 http://tokweweb.uphero.com/
这是给我带来问题的类的代码:
谢谢
public class IconArray {
private ImageIcon[] Icons;
private int Count;
private String Filepath;
IconArray(String filepath, int count){
Count = count;
Icons = new ImageIcon[Count];
Filepath = filepath;
}
IconArray(String filepath, int count, boolean Autoload){
Count = count;
Icons = new ImageIcon[Count];
Filepath = filepath;
if(Autoload){
for(int i = 0; i<Count; i++){
Icons[i] = new ImageIcon(getClass().getResource(Filepath+i+".jpg"));
}
}
}
public Icon GetIcon(final int i) throws InterruptedException{
if(Icons[i]!=null){
return Icons[i];
}else{
Integer temp = new Integer(i);
Icons[i] = new javax.swing.ImageIcon(getClass().getResource(Filepath+temp.toString()+".jpg"));
return Icons[i];
}
}
public int GetCount(){
return Count;
}
}
最佳答案
您的小程序似乎由一个类文件组成。您可能希望将图像与您的类捆绑在 JAR 文件中,如 Using Images in a Swing Applet 中所示。 .
关于java - Icon 类错误,仅在 Web 上显示,而不在 appletviewer 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14794746/