Question

i have a panel in another panel and i want to access an member of the child panel from the parent panel. The child panel reference that is in the parent panel doesn't see all the members that it has. Thanks! PS : the members i can't access are public

Was it helpful?

Solution 2

I made a little test and it works, but on my project doesn't. I think i make a mistake somewhere. Here is the test:

class Main
{
  public static void main(String[] arg)
  {
    MainPanel mp = new MainPanel();
    mp.fct();
  }
}

class MainPanel extends Panel
{
  SecondPanel sp;
  MainPanel()
  {
    sp = new SecondPanel();
  }
  void fct()
  {
    //the mainPanel can access member tf of second panel
    System.out.println(sp.tf.getText());
  }
}

class SecondPanel extends Panel
{
  TextField tf;
  SecondPanel()
  {
    tf = new TextField("Abcde");
    this.add(tf);
  }
}

OTHER TIPS

are you not able to call a getComponents() on the child panel and get all graphical members? If not, the question is not clear enough.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top