View Single Post
  #1 (permalink)  
Old 03-26-2008, 03:36 AM
wco5002 wco5002 is offline
Member
 
Join Date: Mar 2008
Posts: 14
wco5002 is on a distinguished road
Help with actionPerformed Statements
Hi, I'm creating a small photo album that will read images in from an array. The applet will also have a few buttons (first, previous, next, last), which will allow the user to switch to the next photo. However, I'm a little unsure on how to write the actionPerformed statements to switch the photos, hopefully you guys can give me a few pointers. 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) { } }
Reply With Quote
Sponsored Links