ElephantTimer.java



/** 象を成長させるタイマーのクラス */
package zoo;

public class ElephantTimer extends Thread {

  /** 飼育の対象の象 */
    protected Elephant elephant;

  /** 象の取得 */
    public Elephant getElephant() {
        return elephant;
    }

  /** 象の設定 */
    public void setElephant( Elephant ele ) {
        elephant = ele;
    }

  /** 飼育の環境 */
    protected Environment environment;

  /** 環境の取得 */
    public Environment getEnvironment() {
        return environment;
    }

  /** 環境の設定 */
    public void setEnvironment( Environment env ) {
        environment = env;
    }

  /** 表示対象の Viewer */
    protected Viewer viewer;

  /** 環境の取得 */
    public Viewer getViewer() {
        return viewer;
    }

  /** 環境の設定 */
    public void setViewer( Viewer v ) {
        viewer = v;
    }

  /** コンストラクタ */
    public ElephantTimer( Elephant ele,
                          Environment env, Viewer v ) {
        super();
        elephant = ele;
        environment = env;
        viewer = v;
    }

  /** 処理の開始のメソッド */
    public void run() {
        try {
            while( elephant.isAlive() ) {
                elephant.step( environment );
                viewer.repaint();
                Thread.sleep( 1000 );
            }
        }
        catch( Exception e ) {
            System.err.println( e.getMessage() );
            System.exit(-1);
        }
    }
}