473,399 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Help with actionPerformed Statements

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:

Expand|Select|Wrap|Line Numbers
  1. import java.applet.*;
  2. import java.awt.*;
  3. import java.io.*;
  4. import javax.swing.*;
  5. import java.awt.event.*;
  6.  
  7.  
  8. public class Virtual_Photo_Album extends Applet implements ActionListener
  9. {
  10.     private Image imageArr[] = new Image [5];
  11.     private AudioClip myAudioClip;
  12.     private Button firstButton, previousButton, nextButton, lastButton;
  13.  
  14.     public void init() 
  15.     {
  16.        myAudioClip = getAudioClip(getCodeBase(), "../../audio.au");  // Obtians sound clip.
  17.        myAudioClip.loop();   // Loops the audio clip.
  18.  
  19.  
  20.        imageArr[0] = getImage(getCodeBase(),"../../images/image1.jpg");
  21.        imageArr[1] = getImage(getCodeBase(),"../../images/image2.jpg");
  22.        imageArr[2] = getImage(getCodeBase(),"../../images/image3.jpg");
  23.        imageArr[3] = getImage(getCodeBase(),"../../images/image4.jpg");
  24.        imageArr[4] = getImage(getCodeBase(),"../../images/image5.jpg");
  25.  
  26.  
  27.        firstButton = new Button("First");     // Buttons
  28.        firstButton.addActionListener(this);   // Assigns the ActionListeners
  29.        previousButton = new Button("Previous");
  30.        previousButton.addActionListener(this);
  31.        nextButton = new Button("Next");
  32.        nextButton.addActionListener(this);
  33.        lastButton = new Button("Last");
  34.        lastButton.addActionListener(this);
  35.  
  36.        add(firstButton);
  37.        add(previousButton);
  38.        add(nextButton);
  39.        add(lastButton);
  40.     }
  41.  
  42.  
  43.         public void paint (Graphics g) 
  44.         {
  45.             g.drawImage(imageArr[0], 0, 0, this);
  46.             g.drawImage(imageArr[1], 0, 0, this);
  47.             g.drawImage(imageArr[2], 0, 0, this);
  48.             g.drawImage(imageArr[3], 0, 0, this);
  49.             g.drawImage(imageArr[4], 0, 0, this);
  50.         }
  51.  
  52.     public void actionPerformed(ActionEvent e)
  53.     {
  54.  
  55.     }
  56. }
  57.  
Mar 26 '08 #1
1 1451
sukatoa
539 512MB
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:

Expand|Select|Wrap|Line Numbers
  1. import java.applet.*;
  2. import java.awt.*;
  3. import java.io.*;
  4. import javax.swing.*;
  5. import java.awt.event.*;
  6.  
  7.  
  8. public class Virtual_Photo_Album extends Applet implements ActionListener
  9. {
  10.     private Image imageArr[] = new Image [5];
  11.     private AudioClip myAudioClip;
  12.     private Button firstButton, previousButton, nextButton, lastButton;
  13.  
  14.     public void init() 
  15.     {
  16.        myAudioClip = getAudioClip(getCodeBase(), "../../audio.au");  // Obtians sound clip.
  17.        myAudioClip.loop();   // Loops the audio clip.
  18.  
  19.  
  20.        imageArr[0] = getImage(getCodeBase(),"../../images/image1.jpg");
  21.        imageArr[1] = getImage(getCodeBase(),"../../images/image2.jpg");
  22.        imageArr[2] = getImage(getCodeBase(),"../../images/image3.jpg");
  23.        imageArr[3] = getImage(getCodeBase(),"../../images/image4.jpg");
  24.        imageArr[4] = getImage(getCodeBase(),"../../images/image5.jpg");
  25.  
  26.  
  27.        firstButton = new Button("First");     // Buttons
  28.        firstButton.addActionListener(this);   // Assigns the ActionListeners
  29.        previousButton = new Button("Previous");
  30.        previousButton.addActionListener(this);
  31.        nextButton = new Button("Next");
  32.        nextButton.addActionListener(this);
  33.        lastButton = new Button("Last");
  34.        lastButton.addActionListener(this);
  35.  
  36.        add(firstButton);
  37.        add(previousButton);
  38.        add(nextButton);
  39.        add(lastButton);
  40.     }
  41.  
  42.  
  43.         public void paint (Graphics g) 
  44.         {
  45.             g.drawImage(imageArr[0], 0, 0, this);
  46.             g.drawImage(imageArr[1], 0, 0, this);
  47.             g.drawImage(imageArr[2], 0, 0, this);
  48.             g.drawImage(imageArr[3], 0, 0, this);
  49.             g.drawImage(imageArr[4], 0, 0, this);
  50.         }
  51.  
  52.     public void actionPerformed(ActionEvent e)
  53.     {
  54.  
  55.     }
  56. }
  57.  
this may help you out...

try some experiments on it....
doing it so may learn you a lot... and may avoid confusions...

Don't forget to post your questions...

sukatoa
Mar 26 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Geoff | last post by:
Hey, I'm trying to design a simple interface and I'm getting this error: actionPerformed(java.awt.event.ActionEvent) in GUI cannot implement actionPerformed(java.awt.event.ActionEvent) in...
0
by: sandyw | last post by:
Hello Everyone: I need some help with a GUI project. What I want to do is when someone select the File Menu and chose New a Jpanel will open. I have tried to write the code which is called class...
2
by: rookiejavadude | last post by:
I'm have most of my java script done but can not figure out how to add a few buttons. I need to add a delete and add buttong to my existing java program. Not sure were to add it on how. Can anyone...
7
helpwithcode
by: helpwithcode | last post by:
Hi people, I am just learning java.I have been creating a project which involves JDBC Connectivity.I find that the statements, String string_dob=text_dob.getText(); //Converting string to...
2
by: pinkf24 | last post by:
I cannot figure out how to add the following: Modify the Inventory Program to include an Add button, a Delete button, and a Modify button on the GUI. These buttons should allow the user to perform...
0
by: yjh0914 | last post by:
hi guys! so im basically editting my post i made earlier as it wznt as specific.. i have to make a program that basically ranks students by their cumulative gpa. the student's info is on a csv file...
4
by: HxRLxY | last post by:
I am having a compile-time problem with a simple program I am writing. When I attempt to compile, I get the error "non-static variable this cannot be referenced from a static context". The error...
1
by: brendanmcdonagh | last post by:
Hi all, I have my little message program working until i press a button and then it'll go to actionPerformed method, and stop reading but will keep sending a message which is being received....
1
by: onlinegear | last post by:
HI i am writing this for college i know i have loads of combo boxes with nothing in the i havent got that far yet. but every time i run this is comes up with this erro run: Exception in thread...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.