Images used in program
Flipbook video
SlideShow.java
Main Java class, JFrame that holds JPanel
package slideshow;
import javax.swing.JFrame;
public class SlideShow {
public static void main(String[] args) {
JFrame frame = new JFrame("Flipbook");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new slildeShowPanel());
frame.setResizable(false);
frame.pack();
frame.setVisible(true);
}
}
slildeShowPanel.java
SlideShow Panel class, creates JPanel to hold components
package slideshow;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
public class slildeShowPanel extends JPanel{
ImageIcon[] imageArray = new ImageIcon[] {new ImageIcon("one.gif"), new ImageIcon("two.gif"), new ImageIcon("three.gif"),
new ImageIcon("four.gif"), new ImageIcon("five.gif"), new ImageIcon("six.gif") ,
new ImageIcon("seven.gif")};
public JLabel label;
public Timer timer;
public int counter;
public slildeShowPanel()
{
timer = new Timer(100, new timerListener());
timer.start();
label = new JLabel();
counter = 0;
add(label);
setPreferredSize(new Dimension(300, 150));
}
public class timerListener implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
counter++;
if(counter >= imageArray.length)
{
counter = 0;
}
label.setIcon(imageArray[counter]);
}
}
}
No comments:
Post a Comment