classes/MultiBoard.java



import PhotoBoard;
import awt.Graphics;
import awt.Image;
import awt.Color;
import awt.Font;
import java.io.InputStream;
import net.www.html.URL;

/**
  マルチメディア対応のタイトル MultiBoard クラス
 */
class MultiBoard extends PhotoBoard {

       public Image buttonOn, buttonOff;   // ボタンのイメージ
       protected int left, top;            // ボタンの左端と上端の位置
       protected boolean playFlag=false;   // 音を流しているか?
       protected InputStream bgMusic=null; // 音の入力元

    /**
     初期設定の関数。アプレットのサイズを設定。
     */
       protected void init() {

             super.init();    // 親のクラスで定義された処理

             String musicSource = getAttribute("music");
             if( musicSource == null )
                 musicSource
                  = "http://www.wakhok.ac.jp/~tatsuo/hotjava/audio/Sym6.au";
             URL musicURL = new URL( musicSource );
             bgMusic = getContinuousAudioStream( musicURL );

             buttonOn = getImage( "/images/music_rev.gif" );
             buttonOff = getImage( "/images/music.gif" );

             left = width - 42;
             top = height - 43;

             font = getFont( "TimesRoman", Font.ITALIC, 36 );
       }

    /** 
     アプレットの表示(初期状態)を行う関数。
     */
       public void paint( Graphics g ) {

             super.paint( g );    // 親のクラスで定義された処理

             g.setForeground( Color.black );
             g.drawString("Welcome to My HomePage!", photoImage.width+42, 37 );
             g.setForeground( Color.yellow );
             g.drawString("Welcome to My HomePage!", photoImage.width+40, 35 );

             if( playFlag == true )
                g.drawImage( buttonOn, left, top );
             else
                g.drawImage( buttonOff, left, top );
       }

    /** 
     アプレットの表示の変更を行う関数。
     */
       public void update( Graphics g ) {

             if( playFlag == true )
                g.drawImage( buttonOn, left, top );
             else
                g.drawImage( buttonOff, left, top );
       }

    /**
     マウスのボタンが押されると呼び出される関数
     */  
       public void mouseDown( int x, int y ) {
 
             if( bgMusic == null )  return;
             if( x < left || left+32 < x )  return;
             if( y < top || top+32 < y )  return;
 
             if( playFlag == true ) {
                 playFlag = false;
                 stopPlaying( bgMusic );
             }
             else {
                 playFlag = true;
                 startPlaying( bgMusic );
             }

             repaint();
       }
}