Click to See Complete Forum and Search --> : Problem in load .gif file in loop
lordelf2004
May 27th, 2010, 06:03 AM
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!
Norm
May 27th, 2010, 09:10 AM
What class is loadImage() from?
What code displays the image that is loaded?
lordelf2004
May 27th, 2010, 09:56 PM
yes, loadImage() only load my animated image.
lordelf2004
May 31st, 2010, 01:23 AM
somebody helps me??
keang
May 31st, 2010, 05:22 AM
If you answer the questions that Norm has already asked you someone may be able to help you.
lordelf2004
May 31st, 2010, 09:12 PM
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);
}
dlorde
June 1st, 2010, 06:58 AM
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 (http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html).
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
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.