classes/RandomBoard.java
import SimpleBoard;
import BoardCell;
import awt.Graphics;
import awt.Color;
/**
ランダムに絵を表示する RandomBoard クラス
*/
class RandomBoard extends SimpleBoard {
BoardCell cell[][]; // 色を塗るためのセル
protected int iMax,jMax; // セルの縦横の個数
/**
初期設定の関数。アプレットのサイズを設定。
*/
protected void init() {
super.init(); // 親のクラスで定義された処理
iMax = getIntValue( "column" );
if( iMax == 0 ) iMax=4;
jMax = getIntValue( "row" );
if( jMax == 0 ) jMax=4;
width = width - width%iMax;
height = height - height%jMax;
resize( width, height );
cell = new BoardCell[iMax][jMax];
for( int i=0; i<iMax; i++ )
for( int j=0; j<jMax; j++ )
cell[i][j] = new BoardCell( this, i, j,
width/iMax, height/jMax );
}
/**
アプレットの表示(初期状態)を行う関数。
*/
public void paint( Graphics g ) {
super.paint( g ); // 親のクラスで定義された処理
makeTable();
for( int i=0; i<iMax; i++ )
for( int j=0; j<jMax; j++ ) {
if( cell[i][j].toBePainted == true )
cell[i][j].paint( g );
if( cell[i][j].toBePainted == false &&
cell[i][j].isPainted == true )
cell[i][j].clear( g );
}
}
/**
HTMLのデータを受け取り、Strig型からint型に変換する
*/
protected int getIntValue( String keyword ) {
String valueString = getAttribute( keyword );
if( valueString == null ) return 0;
Integer I = new Integer( valueString );
if( I == null ) return 0;
return I.intValue();
}
/**
セルの塗りつぶしの表を作る
*/
protected void makeTable() {
Color color=null;
int r, g, b;
for( int i=0; i<iMax; i++ )
for( int j=0; j<jMax; 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;
}
}
}