Problem with my Slide Show Program
Hi,
In my program which will display some images in a directory, i wrote a seperate thread which is resizing the images and puts them into a JLabel. My problem is, the thread only displays the first image and displays no more (although there are more images in the directory). Below is my code, i am asking for your help
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import java.awt.Toolkit;
import java.io.IOException;
publicclass MyThreadimplements Runnable{
Thread task;
public MyThread(String[] list, JLabel label){
fileList=list;
myLabel=label;
}
publicvoid start()
{
task =new Thread(this);
task.start();
}
publicvoid stop()
{
task =null;
}
publicvoid run()
{
int len=fileList.length;
for(int i=0;i<len;i++){
try{
Image img = Toolkit.getDefaultToolkit().getImage(fileList[i]);
img = img.getScaledInstance(500,500,Image.SCALE_SMOOTH);
ImageIcon myIcon=new ImageIcon(img);
myLabel.setIcon(myIcon);
myLabel.setHorizontalAlignment(JLabel.CENTER);
Thread.sleep(1000);
}catch(Exception ex){}
}
}
String fileList[];
JLabel myLabel;
}
>

