Create an interactive applet named SlideShow that will allow the user to flip through a series of images much like the slides in a slide projector.
To keep things simple, the user will move to the next slide by simply clicking the mouse button.
The SlideShow applet should accept the number of slides and the base image name of the slides as parameters.
Here are the design steps for the SlideShow applet:
The images for the slide show are described as applet parameters, which makes the applet very flexible. Since most slide images are photographs, it's okay to assume that the images are stored in the JPEG image format.
This assumption makes it possible to rely solely on an image base name to describe all of the images in a slide show.
For example, an image base name might be "Vacation". If there are 3 slides in the slide show, then the images.Vacation1.jpg, Vacation2.jpg, and Vacation3.jpg are used.
Before you get started, there is one part of this applet that you are not prepared to develop.
That part is the mouse click code, which involves handling events. To register the mouse event handler, the following line of code should be placed in the applet's
init()
method:
addMouseListener(new MouseHandler());
In addition, the following mouse click handler code should be placed in the applet class definition:
class MouseHandler extends MouseAdapter {
public void mouseClicked(MouseEvent e) {
// Move to the next slide
curSlide = (curSlide + 1) % slides.length;
// Draw the next slide
repaint();
}
}
Placing the class declaration of
MouseHandler
inside the applet makes
MouseHandler
an inner class of the applet.
This allows the
mouseClicked()
method of
MouseHandler
to access the instance methods and variables of the applet.
This code (included in the 03-07 folder as
Mousecode.txt
) handles the details of incrementing the current slide index and repainting the applet window. You also need to import the java.awt.event package in order for the mouse event handling code to compile properly.
In this exercise you will need to convert the
numSlides
from a
String
to an
int
. The static method
parseInt()
in class
Integer
provides this functionality. Here's an example of
parseInt()
in action:
String s = new String("123");
int n = Integer.parseInt(s);
You should have the knowledge and skills to finish the rest of the applet on your own.
The full credit for this exercise is 15 points. To receive full credit, you will need to successfully create the source code for the applet.