Can I do this without reference to the object in the constructor?
In other words, any class inherited from FrmTaoChild when creating must to add the button on the toolbar of the main window
public class FrmTaoMain extends JFrame {
JToolBar tbTask = new JToolBar();
public FrmTaoMain(String Caption) {
super(Caption);
...
FrmTaoChild FrmChild = new FrmTaoChild(tbTask,"test");
}
}
public class FrmTaoChild extends JInternalFrame {
public FrmTaoChild(JToolBar tbTask, String Caption)
{
super (Caption);
JButton btnTask = new JButton(Caption);
tbTask.add(btnTask);
}
}
As discussed in How to Use Internal Frames, “Usually, you add internal frames to a desktop pane.” Instead of passing
JToolBaras a parameter, consider havingFrmTaoChildsupply anActionthatFrmTaoMaincan use for the correspondingJToolBarbutton. See How to Use Actions for more.As an aside, variable names in Java usually begin with lower case.