Wrap around: If there are N images, numbered 0 to N-1, and if the present image is N-1, then if the user hits the Next button, the program should display image number 0. Use an array to store the images when they are loaded into the applet.
You need only 1 class for this problem, one that extends JApplet.
Your class should implement the init() and paint() methods of JApplet class.
Some GUI techniques are needed that have not been covered in the text
up to this point.
For the most part you can model your applet after the PongApplet class
shown on page 699 of Java, Java, Java, 3E except that the class
should implement the ActionListener interface rather than the KeyListener
interface. The getImage() method of JApplet can be used to download images
from the directory where the class code for the applet resides. The
statement
Image myImage = getImage(getCodeBase(), "demo2.gif");
assigns the image in file named demo2.gif to the variable myImage.
The paint() method should be implemented to display
the images. The drawImage() method of the Graphics class can be used
to the display the image in the applet. The statement
g.drawImage(myImage, 0, 100, this);
will display the image with upper left corner of the image
located at left edge of the applet region 100 pixels down from the
upper edge of the applet region. The fillRect() statement can be
used to erase a previous image before displaying the current image
as is done in the PongApplet example. Care should be taken to avoid
erasing the area of the applet where the two buttons are displayed.
Designing an applet using both Graphics drawing commands directly in the
applet content pane and also buttons may cause some display problems
and inconsistencies between platforms. However this design should
suffice to demonstrate a practical use of arrays.
The actionPerformed() method should call repaint() each time the user clicks on one of the buttons. repaint() should also be called at the end of the init() method.