In the ButtonPanel
you're creating a new MainPanel
. This causes you to create a new invisible panel that you're updating.
What you actually need to do, is send the MainPanel
to your ButtonPanel
in it's constructor.
Edit: (disclaimer: all code here is generated without an IDE)
In the PongFrame
constructor do the following:
MainPanel mainPanel = new MainPanel();
ButtonPanel buttonPanel = new ButtonPanel(mainPanel);
This creates a ButtonPanel
with a reference to the MainPanel
.
Now for the ButtonPanel
:
public MainPanel mainPanelReference;
JButton left;
JButton right;
public ButtonPanel(MainPanel mainPanelReference) {
this.left = new JButton("Left");
this.right = new JButton("Right");
add(left);
add(right);
this.mainPanelReference = mainPanelReference;
left.addActionListener(mainPanelReference);
right.addActionListener(mainPanelReference);
}