TestFrame.java



/** 象を飼育する実験のクラス */
package zoo;
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;

public class TestFrame extends JFrame {

  /** 象のオブジェクト */
    public Elephant elephant;

  /** 環境のオブジェクト */
    public VariableFoodEnvironment environment;

  /** Viewerのオブジェクト */
    public Viewer viewer;

  /** NumControlのオブジェクト */
    public NumControl panel;

  /** コンストラクタ */
    public TestFrame() {
        super( "Test Frame" );
        viewer = new Viewer( 256, 192 );
        elephant = new Elephant( "花子" );
        environment = new VariableFoodEnvironment();
        environment.setFoodNum( 10 );
        Toolkit tk = Toolkit.getDefaultToolkit();
        Image image = tk.getImage( "elephant.gif" );
        ElephantPainter painter
            = new ElephantPainter( elephant, image, viewer );
        viewer.setPainter( painter );
        getContentPane().add( viewer, "Center" );
        panel = new NumControl( environment );
        getContentPane().add( panel, "South" );
        pack();
        show();
    }

  /** 処理の開始のメソッド */
    public static void main( String argv[] ) {
        try {
            TestFrame test = new TestFrame();
            ElephantTimer timer
               = new ElephantTimer(
                    test.elephant, test.environment, test.viewer );
            timer.start();
        }
        catch( Exception e ) {
            System.err.println( e.getMessage() );
            System.exit(-1);
        }
    }
}