I have a problem. For example: We have MainFrame, on this form we have mainPanel. Next, creates new classes with names FirstPanel and SecondPanel wich extends JPanel. Now in MainFrame writes:
public MainFrame() {
initComponents();
setLocationRelativeTo(null);
Main main = new Main();
main.setMainPanel(mainPanel);
mainPanel.setLayout( new BorderLayout() );
mainPanel.add( PANELS_LIST.get(0) );
mainPanel.validate();
}
PANELS_LIST - arrayList with all panels. PANELS_LIST.get(0) - jpanel with name FirstPanel . After this we will see FirstPanel. On the FirstPanel we have button. So, on this button click I want to change mainPanel state (need SecondPanel overwrites FirstPanel). How can i do this? Tried to send mainPanel like a param with creating setter or getter but doesn't work.. At all I need mainPanel to be accesable from any panel in any class
PS: ofcourse I can set mainPanel like a public and static, but.. I think this is bad solution