AnimalBoard.java



/** 動物園の動物の情報を表示するボード */
import java.awt.*;
public class AnimalBoard extends Panel {

  /** コンストラクタ */
    public AnimalBoard( Animal ani ) {

        setLayout( new GridLayout( 3, 2 ) );

        Color fg = new Color( 0, 0, 0 );
        Color bg = new Color( 255, 255, 255 );
        Font font = new Font( "TimesRoman", Font.BOLD, 24 );

        String strs[] = { "Name:", ani.name,
                          "Age:", "" + ani.age,
                          "Origin:", ani.getOrigin()
                        };

        Label labs[] = new Label[strs.length];
        for( int i=0; i<strs.length; i++ ) {
            labs[i] = new Label( strs[i] );
            labs[i].setForeground( fg );
            labs[i].setBackground( bg );
            labs[i].setFont( font );
            add( labs[i] );
        }
    }
}