processing animated gifs in JLabels

admin

Administrator
Staff member
Hi there:I created an animated gif file that doesn't loop continuously. It onlyplays once when loaded and that's it. I designed it that way and don'treally want to change it. Now, I've also created a bean I call JGrid,which is nothing more than a collection of JLabels. I've created aproject that makes use of the JGrid bean and during a mouseClick eventI'm loading up the animated gif file into an instance of the ImageIconclass and passing that as an arguement to the JLabel.setIcon(Icon icon)method for that particular JLabel. In my bean I use setIconAt(Icon icon,int row, int col) to specify which JLabel is to receive the image. Thecode in the mouseClick event goes like this:URL url = getClass().getResource("images/explode.gif");//'opponent' is an instance of JGridopponent.setIconAt(new ImageIcon(url), currentRowSelection,currentColSelection);This works, once! If I click on another JLabel in the JGrid I get thegif file alright, but what I getshowing is the last frame of the animated gif. I was expecting it toplay the animated gif file from the beginning again. But it doesn't.Does anyone know how to reset the animated gif file after it has beenrun each and every time?Regards,Alan
 
Back
Top