classes/MultiBoard2.java
import MultiBoard;
import BoardCell;
import awt.Graphics;
import awt.Color;
import awt.Font;
/**
マルチメディア対応のタイトル MultiBoard クラスの改良版
*/
class MultiBoard2 extends MultiBoard implements Runnable {
Thread blinkThread=null; // 画像の移動を行うスレッド
protected int left=8; // セルのアプレット内の位置
protected int right=15; // セルのアプレット内の位置
protected int top=5; // セルのアプレット内の位置
protected int bottom=7; // セルのアプレット内の位置
protected int cell_width=30; // セルの横幅
protected int cell_height=20; // セルの高さ
protected BoardCell cell[][]; // セル
/**
初期設定の関数。
*/
protected void init() {
super.init(); // 親のクラスで定義された処理
cell = new BoardCell[8][3];
for( int i=left; i<=right; i++ )
for( int j=top; j<=bottom; j++ )
cell[i-left][j-top]
= new BoardCell( this, i, j, cell_width, cell_height );
}
/**
アプレットの表示の変更を行う関数。
*/
public void update( Graphics g ) {
if( playFlag == true )
g.drawImage( buttonOn, super.left, super.top );
else
g.drawImage( buttonOff, super.left, super.top );
makeTable();
for( int i=left; i<=right; i++ )
for( int j=top; j<=bottom; j++ )
if( cell[i-left][j-top].toBePainted == true )
cell[i-left][j-top].paint( g );
}
/**
アプレットが続行する作業
*/
public void run() {
while( blinkThread.isAlive() ) {
repaint();
Thread.sleep(500); //一時停止
}
}
/**
アプレットが画面に現れた時に呼び出される。
*/
protected void start() {
if( blinkThread == null ) {
blinkThread = new Thread(this);
blinkThread.start(); //スレッド起動
}
}
/**
アプレットが画面から消えた時に呼び出される。
*/
protected void stop() {
if( blinkThread != null ) {
blinkThread = null; //スレッド停止
}
}
/**
セルの塗りつぶしの表を作る
*/
protected void makeTable() {
Color color=null;
int r, g, b;
for( int i=0; i<8; i++ )
for( int j=0; j<3; j++ ) {
r = (int)( Math.random()*255.0 );
g = (int)( Math.random()*255.0 );
b = (int)( Math.random()*255.0 );
color = new Color ( r, g, b );
cell[i][j].setColor( color );
cell[i][j].toBePainted = true;
}
}
}