Create a Controller class to handle action events.
FramePanel extends JPanel . . FrameController JButton.addActionListener(). FrameController.
public class FrameController implements ActionListener {
private JFrame openedFrame;
public static final int MINIMUM_HEIGHT = 200;
public FrameController(FramePanel panel) {
this.panel.getOpenFrameButton().addActionListener(this);
this.panel.getIncreaseHeightButton().addActionListener(this);
this.panel.getDecreaseHeightButton().addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
String action = e.getActionCommand();
if (action.equals(FramePanel.ACTION_OPEN_FRAME)) {
this.openedFrame = new JFrame();
// set it up how you want it
} else if (action.equals(FramePanel.ACTION_INCREASE_HEIGHT)) {
this.openedFrame.setSize(this.openedFrame.getWidth(), this.openedFrame.getHeight() + 10);
} else if (action.equals(FramePanel.ACTION_INCREASE_HEIGHT)) {
int newHeight = this.openedFrame.getHeight() - 10;
if (newHeight < FrameController.MINIMUM_HEIGHT)
newHeight = FrameController.MINIMUM_HEIGHT;
this.openedFrame.setSize(this.openedFrame.getWidth(), newHeight);
}
}
}