Hi i have a jpanel to draw on. from this jpanel i make bufferedimages and safe them into a linkedlist. on a button press i want to animate this bufferedimages(play one after one) the problem is that the jpanel dont show the buffered images but when i use ImageIO.write to safe the bufferedimages on disk i get all the pictures i want to animate. pls help me.

here is my code:

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);
      } 
}
有帮助吗?

解决方案

The Thread.sleep() causes the GUI to freeze so it can't repaint itself.

To do animation you need to use a Swing Timer.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top