Results 1 to 4 of 4

Thread: Passing object refrences?

Threaded View

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Passing object refrences?

    Im working on a calculator(yes i am that bored) and im am trying to pass a refrence of the enclosing class to a constructor of another class. The object variable calculator is assigned a refrence to the class in the main method and is declared static. Any ideas why this fails to work? Thanks.
    Code:
    public class Calculator{
      static Calculator calculator; 
      public static void main(String[] args){calculator = new Calculator();}
    }
    Code:
    public void addFunctionListeners(JButton[] functions){
        for(int i = 0; i < functions.length; ++i){
          functions[i].addActionListener(new FunctionListener(calculator)); // passing "this" will not work either    
       } 
      }
    Code:
    class FunctionListener implements ActionListener{
      Calculator calculator; 
      public void FunctionListener(Calculator calculator){
       this.calculator = calculator; 
      }
    }

Posting Permissions

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



Click Here to Expand Forum to Full Width