Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-26-2008, 02:36 AM
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) { } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-26-2008, 03:42 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,513
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You have to get the correct action command depend on the buttons action listener. Something like this.
Code:
public void actionPerformed(ActionEvent e) { if("First".equals(event.getActionCommand())){ // Do the processing here } }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-26-2008, 03:50 AM
Member
 
Join Date: Mar 2008
Posts: 14
wco5002 is on a distinguished road
How can I incorporate the repaint() method into this?

Would I have to write something like this:

Code:
public void actionPerformed(ActionEvent e) { if("firstButton".equals(event.getActionCommand())){ g.drawImage(imageArr[0], 0, 0, this) } }
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 03-26-2008, 03:58 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,513
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Did you try it? If so what happened?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 03-26-2008, 04:01 AM
Member
 
Join Date: Mar 2008
Posts: 14
wco5002 is on a distinguished road
I receive two errors:

C:\Users\William\Virtual_Photo_Album\src\Virtual_P hoto_Album.java:69: cannot find symbol
symbol : variable event
location: class Virtual_Photo_Album
if("firstButton".equals(event.getActionCommand())) {
C:\Users\William\Virtual_Photo_Album\src\Virtual_P hoto_Album.java:70: cannot find symbol
symbol : variable g
location: class Virtual_Photo_Album
g.drawImage(imageArr[0], 0, 0, this);
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 03-26-2008, 04:07 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,513
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You have to change the following code

Code:
if("firstButton".equals(event.getActionCommand())){
as

Code:
if("firstButton".equals(e.getActionCommand())){
And also how can you call the line

Code:
g.drawImage(imageArr[0], 0, 0, this)
with out referring the graphic class. At the same time you have miss the semicolon at the end of that line.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by Eranga : 03-26-2008 at 04:47 AM.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 03-26-2008, 04:11 AM
Member
 
Join Date: Mar 2008
Posts: 14
wco5002 is on a distinguished road
Ok, I changed it as you stated, here is what I have then:

Code:
public void actionPerformed(ActionEvent e) { if("firstButton".equals(e.getActionCommand())) { public void paint (Graphics g) { g.drawImage(imageArr[0], 0, 0, this); } } }
But now there are four errors:

C:\Users\William\Virtual_Photo_Album\src\Virtual_P hoto_Album.java:69: illegal start of expression
public void paint (Graphics g)

C:\Users\William\Virtual_Photo_Album\src\Virtual_P hoto_Album.java:69: illegal start of expression
public void paint (Graphics g)

C:\Users\William\Virtual_Photo_Album\src\Virtual_P hoto_Album.java:69: ';' expected
public void paint (Graphics g)

C:\Users\William\Virtual_Photo_Album\src\Virtual_P hoto_Album.java:69: ';' expected
public void paint (Graphics g)

Last edited by Eranga : 03-26-2008 at 04:47 AM.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 03-26-2008, 04:49 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,513
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Yes this is wrong, you can't build a method inside the other. You can call any method within it with correct arguments actually. Just look at last two errors. It outline that after it if condition-loop it expecting statements, not a method.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 03-26-2008, 05:02 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,513
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Is that you have seen buttons on the applet before adding the actionePerformed() in your code?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Issue with Buttons and ActionPerformed Deathmonger Advanced Java 1 04-17-2008 09:47 AM
avoiding if statements valoyivd New To Java 1 04-02-2008 10:08 AM
actionPerformed problem tomitzel New To Java 1 01-08-2008 07:10 PM
Problems with jButton ActionPerformed susan AWT / Swing 3 08-07-2007 05:19 AM
Help with if else statements zoe New To Java 1 07-24-2007 08:56 PM


All times are GMT +3. The time now is 12:01 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org