jpanel non disegnare un'immagine bufferita ma l'immagine bufferita può essere creata come file

StackOverflow https://stackoverflow.com/questions/4888614

Domanda

Ciao ho un jpanel su cui attingere. Da questo jpanel faccio bufferedimages e li ho al sicuro in una lista Linked. Su un pulsante Premere voglio animare questo bufferedImages (riproduci uno dopo uno) il problema è che il jpanel non mostra le immagini buffered ma quando uso ImageIo.Rite per al sicuro le bufferedImages sul disco ottengo tutte le immagini che voglio animare. pls aiutami.

Ecco il mio codice:

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);
      } 
}
È stato utile?

Soluzione

Il thread.sleep () fa congelare la GUI in modo che non possa ridipingere se stessa.

Per fare l'animazione devi usare un'altalena Timer.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top