2012-04-20 4 views
0

コンポジットの理解に問題があります。 FrameクラスでJavaまたはGWTでコンポジットを理解する

私が持っているVPがロードされているverticalPanel(VP)、getActionとButtonを取得することはVP上に表示されている

ボタンをクリックがgetTreeがあるときに実行され、そこにカスタマイズされた初期化treeCクラスが存在しています木。およびツリーアイテム。

私はそれを行うにはどのようにクラスTreeC

にアクションオブジェクトを使用します。

Plzヘルプ。

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*/ 
} 
} 

答えて

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

+0

感謝を作成したとき、私は同じことをしました。すべてのコンポジットが同じクラスにあるので、他にもオプションがあると思いました。 – NewCodeLearner

関連する問題