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;

}

>

[2553 byte] By [acartamersoya] at [2007-11-27 11:19:27]
# 1

It seems to be ok. I guess you are sure you pass the right list to the constructor. Then I think you only need to call repaint().

Ja_Lava_Javaa at 2007-7-29 14:36:49 > top of Java-index,Java Essentials,Java Programming...
# 2

Problem solved.

fileList in my code is a String array that holds the filenames not the canonical file paths. I changed it to File array and used canonical paths when getting the images. Interesing thing is, code below worked for one image, i never thought there was a problem when getting the images.

Thanks for the help Ja_Lava_Java

acartamersoya at 2007-7-29 14:36:49 > top of Java-index,Java Essentials,Java Programming...