RepeatedImage.java
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
/** イメージを複数個並べて表示する RepeatedImage クラスの定義 */
public class RepeatedImage extends Applet {
/** イメージ */
public Image image = null;
/** イメージ */
public int number = 1;
/** 初期設定のメソッド */
public void init() {
String source = getParameter("source");
if( source != null )
image = getImage( getDocumentBase(), source );
else
image = getImage( getCodeBase(), "default.gif" );
number = getIntValue("number");
}
/** アプレットの表示を行うメソッド */
public void paint( Graphics g ) {
int w = image.getWidth( this ); // イメージの横幅
int h = image.getHeight( this ); // イメージの高さ
g.drawImage( image, 0, 0, this ); // 読み込みを開始させるため
if( w<=0 || h<=0 ) return; // サイズ未確定なら何もしない
// アプレットのサイズに合わせてタイルを縦横に張り込む
for( int i=0; i<number; i++ )
g.drawImage( image, i*w, 0, this );
}
/** パラメータの文字列を解釈するメソッド */
protected int getIntValue( String name ) {
String word = getParameter( name );
if( word == null ) // 値が与えられていない
return 1;
int value = Integer.parseInt( word );
if( 0 <= value || value <= 100 ) // 適切な値の範囲
return value;
else
return 1;
}
}