Results 1 to 4 of 4
Thread: Help with Calling a method
- 07-04-2007, 09:42 AM #1
Senior Member
- Join Date
- Jun 2007
- Posts
- 114
- Rep Power
- 0
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:
Java 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(); }
Albert:rolleyes:
- 07-04-2007, 09:43 AM #2
Member
- Join Date
- Jun 2007
- Posts
- 95
- Rep Power
- 0
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:p
- 07-04-2007, 09:46 AM #3
Member
- Join Date
- Jun 2007
- Posts
- 91
- Rep Power
- 0
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:o
- 07-10-2007, 04:27 PM #4
Member
- Join Date
- Jul 2007
- Posts
- 5
- Rep Power
- 0
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.
Similar Threads
-
Calling a method in another class
By uncopywritable in forum New To JavaReplies: 9Last Post: 10-22-2012, 05:01 PM -
Dynamic method calling
By Java Tip in forum Java TipReplies: 0Last Post: 02-15-2008, 09:46 AM -
method calling?
By frejon26 in forum New To JavaReplies: 4Last Post: 01-25-2008, 04:38 AM -
i'm no good in calling Method please help
By lowpro in forum New To JavaReplies: 1Last Post: 11-26-2007, 06:15 PM
Bookmarks