So... it looks like the 2 parts to your system need to know about each other - or at least ButtonPanel needs to have access to the instance of GamePanel so it can call its methods.
One way is to pass the instance of GamePanel to ButtonPanel in ButtonPanel's constructor. ButtonPanel can then keep a copy of that and use it to call GamePanel's methods
game = new GamePanel();
ButtonPanel buttons = new ButtonPanel(game);
...
public class ButtonPanel...
private GamePanel game;
public ButtonPanel(GamePanel game) {
this.game = game;
...
}
...
game.initalizeNewGame()
JamesCherrill
Posting Genius
6,370 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
Kindof... you need to run one constructor to get the object to pass to the other constructor, so the simple version only works for passing one way. You can pass both ways by doing something like
game = new GamePanel();
ButtonPanel buttons = new ButtonPanel(game);
buttons.setGamePanel(game); // need to define this method in ButtonPanel class
ps. This is pushing the boundary of doing things in a single layer - if you had a third panel you would definitely be better off by going to an MVC architecture (or at least VC) where your Panels are the views, and a new Controller class has responsibility for creating all the views and handling all the logic between them. In that case each view class just needs a reference to the controller, not to any of the other views.
JamesCherrill
Posting Genius
6,370 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073