i cannot make this slideshow code work. It only shows the last image in the Image objects arraylist...
does anyone have a clue? thanks a lot
/*
* SlideshowPlayer.java
*
* Created on September 4, 2007, 3:34 PM
*/
package slideshow;
import java.awt.*;
import java.util.ArrayList;
/**
*
* @author joey
*/
public class SlideshowPlayer extends javax.swing.JFrame {
ArrayList <Image> images = new ArrayList();
Image imageToDisplay;
int width = 0;
int height = 0;
MediaTracker mt = new MediaTracker (this);
/**
* Creates new form SlideshowPlayer
*/
public SlideshowPlayer(Slideshow slideshow) {
initComponents();
setBackground(Color.black);
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(this);
width=this.getWidth();
height=this.getHeight();
for (int i=0;i<slideshow.pictures.size();i++){
images.add(Toolkit.getDefaultToolkit().createImage(slideshow.pictures.get(i).getPicturePath()));
}
imageToDisplay=images.get(0);//the first image is prepared
mt.addImage(imageToDisplay, 0);//and displayed
for (int i=1; i<images.size(); i++){
this.changeImage(images.get(i), i);
try {
Thread.sleep(3000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
public void changeImage(Image newImage, int i){
mt.removeImage(imageToDisplay);
imageToDisplay=newImage;
if (imageToDisplay.getWidth(this)>width){
imageToDisplay = imageToDisplay.getScaledInstance(width, height, imageToDisplay.SCALE_DEFAULT);
}
mt.addImage(imageToDisplay, i);
this.update(this.getGraphics());
}
public void update(Graphics g){
paint(g);
}
public void paint(Graphics g){
if(imageToDisplay != null){
g.drawImage(imageToDisplay, width/2-imageToDisplay.getWidth(this)/2, height/2-imageToDisplay.getHeight(this)/2, this);
}
else{
g.clearRect(0, 0, getSize().width, getSize().height);
System.out.println("no image to display");
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
setBackground(new java.awt.Color(0, 0, 0));
setUndecorated(true);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 325, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
/* public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new SlideshowPlayer().setVisible(true);
}
});
}*/
// Variables declaration - do not modify
// End of variables declaration
}