嗨,我有一个 jpanel 可供使用。从这个 jpanel 我制作缓冲图像并将它们安全到链表中。在按下按钮时,我想为这个缓冲图像设置动画(一个接一个地播放)问题是 jpanel 不显示缓冲图像但是当我使用 ImageIO.write 来保护磁盘上的缓冲图像时,我得到了我想要动画的所有图片。请帮助我。
这是我的代码:
public void run(){
for(int i=0;i`<`cm.animationListe.size();i++){
b= cm.animationListe.get(i);
try {
ImageIO.write( b, "png", new File( "c:/java/circle"+i+".png" ) );
} catch (IOException e1) {
e1.printStackTrace();
}
try {
Thread.sleep(1000);
repaint();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}
animation = false;
}
public void paintComponent(Graphics g){
super.paintComponent(g);
if(animation){
g.drawImage(b,0, 0,null);
}
}