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 07-04-2007, 09:42 AM
Senior Member
 
Join Date: Jun 2007
Posts: 114
Albert is on a distinguished road
Help with Calling a method
Hi I can't figure out how to make this part of my program work.. it keeps saying cannot find member variable g even though it worked in the paint method..
here's the code:
Code:
public void actionPerformed(ActionEvent ae) { EightBall displayAnswer = new EightBall(); EightBall answer = new EightBall(); String sMessage = ae.getActionCommand(); if( sMessage.equals("Ask")) { remove(text); remove(askButton); add(resetButton); displayAnswer.displayAnswerTwo(g); //cannot find symbol variable g } if(sMessage.equals("Reset")) { remove(resetButton); add(text); add(askButton); answer.displayAnswer (g); //cannot find symbol variable g } repaint(); }
Thanks.
Albert
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-04-2007, 09:43 AM
Member
 
Join Date: Jun 2007
Posts: 95
Felissa is on a distinguished road
With the amount of code you have shown I have to agree with the compiler.
I cannot find member variable g either.
Where in your code is g actually defined?

Greetings.
Felissa
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-04-2007, 09:46 AM
Member
 
Join Date: Jun 2007
Posts: 92
Daniel is on a distinguished road
As Felissa said, can we see perhaps the entire class?

That way we can find out where it is, and why it doesn't see it in its scope.

To be honest, your compiler probably isn't lying, and it probably can't see that member variable.

Are you sure it's not declared outside of the class?

Greetings
Daniel
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-10-2007, 04:27 PM
Member
 
Join Date: Jul 2007
Posts: 5
olatunbode is on a distinguished road
I think i understand what the problem is, even without seeing most of the code. In the method: public void paint(Graphics g), g has a local scope and so u cannot use it in another method (actionPerformed in this case), except you pass the g from paint() into the method you are referring g from. But since ur method is actionPerformed, i guess ur program has to be restructured.

Hope i was helpful.
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
Dynamic method calling Java Tip Java Tips 0 02-15-2008 09:46 AM
method calling? frejon26 New To Java 4 01-25-2008 04:38 AM
Calling a method in another class uncopywritable New To Java 8 01-14-2008 05:37 PM
i'm no good in calling Method please help lowpro New To Java 1 11-26-2007 06:15 PM


All times are GMT +3. The time now is 10:47 AM.


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