Hello, let's say I have these classes:
public class ClassA extends JFrame{
private JButton btn1;
private JPanel panel;
public JPanel getPanel(){
return this.panel;
}
ClassA(){
this.setSize(500,500);
this.setVisible(true);
panel=new JPanel(new FlowLayout());
btn1=new JButton("LALALA");
this.add(panel);
panel.add(btn1);
}
}
public class ClassB {
ClassA a;
ClassB(ClassA a){
this.a = a;
JButton button2 = new JButton("leButton");
a.getpanel().add( button2 );
}
}
I guess it doesn't make much sense to declare + initialize a component in a class and then add it to another class extending a JFrame. What would happen if the object where the component is initialized were destroyed ?
Presuming you understand my question, what can I do and how? should I just add the button from classA, hide it and then make it visible from class B when I need to?
Thanks.