Hey, I'm writing a simple program that stores several images in an array and allows the user to switch the images via a few buttons (first, previous, next, last) I've managed to get most of the code working, but I'm not sure how to write the actionPerformed statements to allow the buttons to transition the code, here is the code thus far:
Code:
import java.applet.*; import java.awt.*; import java.io.*; import javax.swing.*; import java.awt.event.*; public class Virtual_Photo_Album extends Applet implements ActionListener { private Image imageArr[] = new Image [5]; private AudioClip myAudioClip; private Button firstButton, previousButton, nextButton, lastButton; public void init() { myAudioClip = getAudioClip(getCodeBase(), "../../audio.au"); // Obtians sound clip. myAudioClip.loop(); // Loops the audio clip. imageArr[0] = getImage(getCodeBase(),"../../images/image1.jpg"); imageArr[1] = getImage(getCodeBase(),"../../images/image2.jpg"); imageArr[2] = getImage(getCodeBase(),"../../images/image3.jpg"); imageArr[3] = getImage(getCodeBase(),"../../images/image4.jpg"); imageArr[4] = getImage(getCodeBase(),"../../images/image5.jpg"); firstButton = new Button("First"); // Buttons firstButton.addActionListener(this); // Assigns the ActionListeners previousButton = new Button("Previous"); previousButton.addActionListener(this); nextButton = new Button("Next"); nextButton.addActionListener(this); lastButton = new Button("Last"); lastButton.addActionListener(this); add(firstButton); add(previousButton); add(nextButton); add(lastButton); } public void paint (Graphics g) { g.drawImage(imageArr[0], 0, 0, this); g.drawImage(imageArr[1], 0, 0, this); g.drawImage(imageArr[2], 0, 0, this); g.drawImage(imageArr[3], 0, 0, this); g.drawImage(imageArr[4], 0, 0, this); } public void actionPerformed(ActionEvent e) { } }
Comment