ElephantBoard.java



/** 象の情報を表示するボード */
import java.awt.*;

public class ElephantBoard {

  /** コンストラクタ */
    public ElephantBoard( Elephant ele ) {

        Frame frame = new Frame( ele.name );
        frame.setLayout( new GridLayout( 3, 2 ) );

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

        String strs[] = { "Name:", ele.name,
                          "Age:", "" + ele.age,
                          "Origin:", ele.origin
                        };

        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 );
            frame.add( labs[i] );
        }

        frame.pack();  // frameのサイズの自動調整
        frame.show();  // frameの表示
    }
}