PandaBoard.java



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

public class PandaBoard {

  /** コンストラクタ */
    public PandaBoard( Panda pan ) {

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

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

        String strs[] = { "Name:", pan.name,
                          "Age:", "" + pan.age,
                          "Origin:", pan.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の表示
    }
}