ElephantPainter.java



/** 象の表示の処理を実行するクラス */
package zoo;
import java.awt.*;
import java.awt.image.*;
import java.awt.geom.*;

public class ElephantPainter implements Painter {

 /** Elephantのオブジェクト */
    protected Elephant elephant=null;

 /** Imageのオブジェクト */
    protected Image image=null;

 /** ImageObserverのオブジェクト */
    protected ImageObserver observer=null;

 /** コンストラクタ */
    public ElephantPainter( Elephant e,
                            Image i, ImageObserver io ) {
        super();
        elephant = e;
        image = i;
        observer = io;
    }

 /** 描画の処理の実装 */
    public void paint( Graphics2D g ) {
        double s = ((double)elephant.getWeight())/100.0;
        g.drawImage( image,
                     AffineTransform.getScaleInstance( s, s ),
                     observer );
    }
}