我在另一个面板中有一个面板,我想从父面板访问子面板的成员。父面板中的子面板引用看不到它拥有的所有成员。谢谢!PS:我无法访问的成员是公开的
问问题
64 次
2 回答
0
您不能getComponents()
在子面板上调用 a 并获取所有图形成员吗?如果不是,则问题不够清楚。
于 2010-04-13T17:00:18.363 回答
0
我做了一个小测试,它有效,但在我的项目中没有。我想我在某个地方犯了一个错误。这是测试:
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);
}
}
于 2010-04-13T17:25:32.953 回答