1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
import java.io.*;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
public class Diaporama extends JFrame implements Runnable {
private static final long serialVersionUID = 1L;
private String folder;
private String[] images;
private int index;
private JLabel image;
public Diaporama(File folder) {
super("Diaporama");
images = folder.list();
this.folder = folder.getAbsolutePath();
index = 0;
setSize(800, 600);
image = new JLabel();
add(new JScrollPane(image));
setVisible(true);
//setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void lireImage(String imageName) throws IOException {
System.out.println(folder + imageName);
image.setIcon(new ImageIcon(ImageIO.read(new File(folder + "\\"
+ imageName))));
}
public void run() {
while (true) {
try {
lireImage(images[index]);
} catch (IOException e) {
e.printStackTrace();
} catch (NullPointerException e) {
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
index = (index + 1) % images.length;
}
}
public static void main(String[] args) {
Diaporama diap = new Diaporama(new File("C:\\Images"));
new Thread(diap).start();
}
} |
Partager