我在理解复合材料时遇到问题。
在Frame类中,当vp加载时,我具有verticalPanel(vp),在vp上可见getAction和get Button
当单击按钮时,将执行一个getTree,并且在有定制树的地方初始化了treeC类。和treeitem。
我想在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*/
}
}
最佳答案
最简单的方法是:
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);
时