【发布时间】:2017-06-23 23:22:02
【问题描述】:
我正在尝试将 GIF 文件显示到 JLabel。没问题我加载GIF并将其设置为标签的图标。但现在我真的需要知道什么时候结束,因为它必须充当过场动画。我已经尝试过的是这个(GameScene 是一个自定义对象,但我知道 setIcon 有效,相信我):
private GameScene scene;
private ImageIcon _temp;
private ImageIcon toplay;
private Thread anim;
public Cutscene(ImageIcon gif, GameScene scene, int length){
this._temp = scene.getIcon();
this.toplay = gif;
this.scene = scene;
anim = new Thread(){
@Override
public void run(){
scene.setIcon(gif);
scene.repaint();
try {
Thread.sleep(length);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
}
private void _s(){
scene.setSolidColor(false);
scene.setIcon(toplay);
scene.repaint();
}
public void play(){
_s();
anim.start();
}
public void await(){
try {
anim.join();
scene.setIcon(_temp);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
现在,我有没有办法做到这一点,只需让整个程序休眠给定的时间,然后继续执行其余代码并且完全不绘制 GIF 文件?
【问题讨论】:
-
不是以“直截了当”开头的问题。
-
你没看错吧?