开发者

Problem with imbricate panels in java

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


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.


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);
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜