Your buttonpanel requires a reference to ParentFrame
to be constructed. ButtonPanel
is being constructed in parent frame and creating a listener, which references the parent frame's button panel.
Unfortunately, the button panel hasn't been assigned at that point, and so your action listener has a null value assigned to its instance of button panel.
I think the problem is your button panel instance is null in your AddButtonListener
.
You can fix this by passing a ButtonPanel instance into your AddButtonListener
constructor. As AddButtonListener
isn't using ParentFrame
, don't bother passing it at all.
private ButtonPanel buttonPanel;
public AddButtonListener(ButtonPanel panel){
myFrame = parent;
buttonPanel = panel;
}
And then in your button panel constructor:
public ButtonPanel(ParentFrame parent){
parentFrame = parent;
buttonStatus = "idle";
//Create Buttons
AddButtonListener buttonListener = new AddButtonListener(this);
//rest the code
Aside, you shouldn't be structuring things like this. What you're doing is tightly coupling your ButtonPanel
with your ParentFrame
. This means if your parent frame changes it could cause another change in ButtonPanel
, which makes for less maintanable code.