Accessing "parent" methods
807591Apr 14 2008 — edited Apr 15 2008I have a JPanel (let's call it mainPanel) that creates (and contains) a few classes that extend JPanels (panel1, panel2). panel1 and panel2 are "set up" with all their components in their own default constructors.
Is it possible for panel1 to access panel2? eg if a button is pressed on panel1, can it make a label change its value on panel2? I can do it by adding all the components for panel1 and panel2 (or at least one of them) on mainPanel. Thus if the button was created in mainPanel and inserted into panel1, clicking it would allow mainPanel to call a set method in panel2 to change the label.
To give more background to the problem, I have a window which is divided into a few sections using panels with a titled borders. I did this so that the window can have pieces of functionality "grouped" in framed panels. The solution I offered will make the code in mainPanel extremely messy as every component will be made there rather than where they naturally would be expected.
To clarify the problem once more, is it possible for a class to access a parent method to in turn access a sibling method, where 'parent' is not in the regular context of inheritance, but rather it is the class that created the class in question.
Any help would be much appreciated.