2009-08-13 8 views
0

コンポーネントベースのプロジェクトを実装するのに助けてくれる人はいますか?私はスイングコンポーネント(JListJTree、またはanyのいずれか)の内側にある必要がある電卓とエンジンの2つのコンポーネント(以下のソースコード)を設計しました。次に、2つのコンポーネント(電卓またはエンジン)のいずれかをエディタペインにドラッグしてコネクタを使用して合成できるようにする機能があります(以下のコードを参照)。コンポジションが正しい場合は、コンポジットを最初のコンポーネントがドラッグされたパレットに戻します。コンポーネントベースの構成

コンポーネント:

public class Engine { 

    private String name = ""; 
    private boolean running = false; 
    private int speed; 

    public Engine(String name) { 
     this.name = name; 
    } 

    public void start() { 
     if (!running) { 
      running = true; 
      System.out.println("Engine starts."); 
     } 
     else 
      System.out.println("Engine already starts."); 
    } 

    public void stop() { 
     if (running) { 
      running = false; 
      speed = 0; 
      System.out.println("Engine stops."); 
     } 
     else 
      System.out.println("Engine already stops."); 
    } 

    public void setSpeed(int speed) { 
     if (speed >=0) 
      this.speed = speed; 
    } 
} 

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

public class Calc { 

    public Calc() { 

     } 

    public Double squareRoot(Double a_double){ 
     return Math.sqrt(a_double); 
    } 

    // pre an_int >= 0 
    public synchronized Integer factorial(Integer an_int){ 
     int fact=1; 
     for(int i=1;i<=an_int;i++){ 
      fact *= i; 
     } 
     return fact; 
    } 

    /** 
    * 
    * @param an_int 
    * @return the squared root of the input integer 
    */ 
    public Integer getSquareRoot(Integer an_int){ 
     return (int) Math.sqrt(an_int); 
    } 


    public Double getSquareRoot(Double aDouble){ 
     return Math.sqrt(aDouble); 
    } 

    /** 
    * Converts an Integer object into a Double object. 
    * 
    * @param an_int The Integer to be converted. 
    * @return The Double object representing the same value. 
    * 
    */ 
    public Double integerToDouble(Integer an_int){ 
     return new Double(an_int.intValue()); 
    } 

    /** 
    * Converts a Double object into an Integer object. Decimal digits are 
    * truncated. Useful when passing the output of a method as the input to another. 
    * 
    * @param a_double The Double to be converted. 
    * @return The Integer object representing the same value. 
    * 
    */ 
    public Integer doubleToInteger(Double a_double){ 
     return new Integer(a_double.intValue()); 
    } 


    public Integer sum(Integer a, Integer b) { 
     try { 
      Thread.sleep(2000); 
     } catch (InterruptedException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     return a+b; 
    } 

    /** 
    * Returns a string representation of the calculator. 
    */ 
    public String toString(){ 
     return("Calculator computation unit:\n"+super.toString()); 
    } 


    void doNothing(){ 

    }} 

///////////////////////////// ///////////////////////////////////////////////////////////////// //////////

+0

なぜプリミティブではなくボックス入りの数字を使用していますか? –

答えて

0

おそらくNetbeansのGUIエディタがうまくいっていると思われる既存のGUIエディタを活用するのがよいでしょう。

コンポーネントをコンポーネントパレットに追加する必要があります。詳細については、Netbeansオンラインヘルプを参照してください。

関連する問題