ImageBoard.java



import java.awt.Graphics;
import java.awt.Image;

/** イメージをレイアウトして描く ImageBoard クラスの定義 */

public class ImageBoard extends RGBArea {

    /** 表示するイメージ */

       public Image image = null;

    /** 初期設定のメソッド */

       public void init() {

             super.init();  // スーパークラスの init() を呼ぶ

             String source = getParameter("source");    // イメージのソース名
             if( source != null )
                 image = getImage( getDocumentBase(), source );   // 指定あり
             else
                 image = getImage( getCodeBase(), "default.gif" );// 指定なし
       }

    /** アプレットの表示を行うメソッド */

       public void paint( Graphics g ) {

             int w = image.getWidth( this );   // イメージの横幅
             int h = image.getHeight( this );  // イメージの高さ
             int x = ( size().width - w )/2;
             int y = ( size().height - h )/2;

             g.drawImage( image, x, y, this );    // イメージを表示
       }

    /** イメージの更新時に呼び出されるメソッド */

       public boolean imageUpdate( Image img, int flags,
                                   int x, int y, int w, int h ) {

             if( ( flags & ALLBITS ) == ALLBITS ) {
                 repaint();     // イメージが完成した時のみ再表示
                 return false;
             }
             else {
                 return true;
             }
       }
}