Problem in load .gif file in loop
Hii all,
to make my program more interactive, I try to load one .gif file whenever it has a loop. But the animation in loop do not operate until the loop ends. Certainly, it ruins my purpose...
my code like this:
/*
loadImage("processingImage.gif"); //embed animation image in label object.
for(int i = 0; i....; ....){
}//end loop
*/
My animated image paused during the loop. It only operates after the loop ends..
Please help me to explain this situation. And give me the solution...
Thanks all in advance!
Re: Problem in load .gif file in loop
What class is loadImage() from?
What code displays the image that is loaded?
Re: Problem in load .gif file in loop
yes, loadImage() only load my animated image.
Re: Problem in load .gif file in loop
Re: Problem in load .gif file in loop
If you answer the questions that Norm has already asked you someone may be able to help you.
Re: Problem in load .gif file in loop
hii keang,
This is my loadImage function:
public void loadImage(){
GIF_Label = new javax.swing.JLabel();
GIF_Label.setSize(270, 168);
GIF_Label.setLocation(20, 20);
ImageIcon ii = new ImageIcon(this.getClass().getResource("Processing2.gif"));
GIF_Label.setIcon(ii);
this.getContentPane().add(GIF_Label);
}
Re: Problem in load .gif file in loop
You're not giving the Swing EDT (Event Dispatcher Thread) a chance to display the image because your loop is running in the same thread. To update the Swing GUI, either put the loop code in a SwingUtilities.invokeLater call, or use a SwingWorker thread. See Concurrency In Swing.
In the development of the understanding of complex phenomena, the most powerful tool available to the human intellect is abstraction. Abstraction arises from the recognition of similarities between certain objects, situations, or processes in the real world and the decision to concentrate on these similarities and to ignore, for the time being, their differences...
C.A.R. Hoare