Question
Java Slideshow Application Write an application that displays a slideshow of images, one after the other, a time delay between each images. The user should
Java Slideshow Application
Write an application that displays a slideshow of images, one after the other, a time delay between each images. The user should be able to select up to 10 image for the slideshow for every 1000 msec.
I am getting error on this code: timer = new Timer(TIME_DELAY, new TimerListener());
/****************code*************/
ImageSlideShow.java
//import packages import javax.swing.*; import java.awt.event.*; import java.awt.*;
//ImageSlideShow.java public class ImageSlideShow extends JApplet { //time delay private final int TIME_DELAY = 1000; private Timer timer; //timer object private Image image; //image object private int index = 0; //image strings array private String[] imgArray = { "ca.gif","denmark.gif","france.jpg", "germany.gif","india.gif","japan.gif", "philippines.jpg","UAE.gif","uk.gif", "us.gif" }; //init() method must be called to start the applet with //250 px width, 250 px height public void init() { //set size of applet setSize(250,250); //set starting image to display image = getImage(getDocumentBase(), imgArray[index]); //create timer object to start slideshow timer = new Timer(TIME_DELAY, new TimerListener()); //set timer to start the slide show every 1000 msec timer.start(); } //end of init method /*Paint method overrides the applet surface *area by drawing image width of 250 px and *250 px high*/ public void paint(Graphics g) { //Call the superclass paint method super.paint(g); //Draw the ball g.drawImage(image, 0,0,250,250,this); } //end of paint method /*private inner class to manage the Timer Object's *events*/ private class TimerListner implements ActionListener { public void actionPerformed(ActionEvent e) { if(index<10) index++; if(index==imgArray.length) index=0; //rewrite the applet panel with image image = getImage(getDocumentBase(), imgArray[index]); //Force paint method call repaint(); } }//end of inner class TimerListener }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started