Results 1 to 4 of 4
  1. #1
    Albert is offline Senior Member
    Join Date
    Jun 2007
    Posts
    114
    Rep Power
    0

    Default 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();
        }
    Thanks.
    Albert:rolleyes:

  2. #2
    Felissa is offline Member
    Join Date
    Jun 2007
    Posts
    95
    Rep Power
    0

    Default

    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

  3. #3
    Daniel is offline Member
    Join Date
    Jun 2007
    Posts
    91
    Rep Power
    0

    Default

    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

  4. #4
    olatunbode is offline Member
    Join Date
    Jul 2007
    Posts
    5
    Rep Power
    0

    Default

    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

  1. Calling a method in another class
    By uncopywritable in forum New To Java
    Replies: 9
    Last Post: 10-22-2012, 04:01 PM
  2. Dynamic method calling
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-15-2008, 08:46 AM
  3. method calling?
    By frejon26 in forum New To Java
    Replies: 4
    Last Post: 01-25-2008, 03:38 AM
  4. i'm no good in calling Method please help
    By lowpro in forum New To Java
    Replies: 1
    Last Post: 11-26-2007, 05:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •