0

我在理解复合材料方面有问题。

在 Frame 类中,当加载 vp 时,我有 verticalPanel(vp),getAction 和 get Button 在 vp 上可见

当单击按钮时,执行 getTree 并且在自定义树的位置初始化了 treeC 类。和树项。

我想在 TreeC 类中使用动作对象

怎么做。

请帮助。

public class Frame{
public frame () {
    initWidget(getFramePanel());
}
Private VerticalalPanel getFramePanel() { 
    if (vp== null) {
        vp= new VerticalalPanel();
        vp.setSize("1442px", "750px");
        vp.add(getAction());// **are composites**
        vp.add(getButton) // **are composite**

    }
    return vp;

private Action getAction() {
        if (action == null) {
            action = new Action(); // In action class there are 7 buttons and 2 methods //setDisplayRepository(), and setDisplayFolder()
            action.setDisplayRepository();
        }
        return action;
    }
}
private Button getButton() {
        if (btn == null) {
            btn = new Button("Click");
            btnProperties.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    hp.add(getTree());
                }
            });
            btn.setSize("37px", "36px");

        }
        return btnProperties;
    }

private TreeCmis getTreeC() {
        if (treeC == null) {
            treeC = new TreeC();
            treeC.setWidth("360px");
        }
        return treeCmis;
    }
}

public class TreeC extends Composite{
private Tree repo;
//constructor
public TreeC {

createTree()
}
Void createTree(){
/* here i need to to use the object action declared in frame class
For using action.setDisplayfolder*/
}
}
4

1 回答 1

1

最简单的方法是:

public class TreeC extends Composite{
  private Tree repo;
  private Action action;
  //constructor
  public TreeC(Action action) {
   this.action = action;
   createTree()
  }
  void createTree(){
   /* here i need to to use the object action declared in frame class
   For using action.setDisplayfolder*/
  }
}

创建实例时 treeC = new TreeC(action);

于 2012-04-20T09:43:58.887 回答