Hi, I am new to programming, and trying to learn by making a few simple programs.
My problem involves passing a reference between classes.
I learned how to pass references via constructors, but now I have run into a dilemma. I want to pass a reference of two objects to each other, but have run into the problem that one must be created before the other in order to reference it. it's kind of a chicken and egg situation.
TimerPanel timer = new TimerPanel(input); InputPanel input = new InputPanel(control); panel.add (timer); panel.add (input);
The constructors of each class will accept a reference of the other, but obviously, with this code, when I try to pass the variable input to the new TimerPanel, it cannot find input because it hasn't been created yet, and tells me the symbol cannot be found.
Does anyone know how to fix this? Any help would be greatly appreciated. Thanks!