クラスの継承を利用してアプレットを開発する例です。 空欄を埋めてプログラムを完成させなさい。
import java.applet.Applet;
/** Appletに汎用の機能を追加した ParamApplet クラス */
abstract public class ParamApplet [ ] Applet {
/** パラメータの文字列を int型に変換するメソッド */
protected int getIntParameter( String word ) throws Exception {
String valueString = getParameter( word );
if( valueString == null )
[ ] new Exception(); // 例外が発生
[ ] {
return Integer.parseInt( valueString );
}
catch( NumberFormatException e ){
[ ] e; // 例外が発生
}
}
/** パラメータの文字列を float型に変換するメソッド */
protected float getFloatParameter( String word ) throws Exception {
String valueString = getParameter( word );
if( valueString == null )
[ ] new Exception(); // 例外が発生
[ ] {
return Float.valueOf( valueString ).floatValue();
}
catch( NumberFormatException e ){
[ ] e; // 例外が発生
}
}
}
import java.awt.Color;
/** 色をRGB値で指定できる RGBArea クラス */
public class RGBArea [ ] [ ] {
/** アプレットの背景色*/
Color bgcolor;
/** 初期設定のメソッド(生成時に自動的に呼ばれる)*/
public void init() {
[ ] {
int red = getIntParameter("red"); // Red成分の値
int green = getIntParameter("green"); // Green成分の値
int blue = getIntParameter("blue"); // Blue成分の値
if( 0<=red && red<=255 &&
0<=green && green<=255 &&
0<=blue && blue<=255 ) {
bgcolor = new Color( red, green, blue ); // 色を生成
}
else
bgcolor = Color.white; // デフォルト値(白)
}
[ ]( NumberFormatException e ){ // 形式がおかしい
bgcolor = Color.white; // デフォルト値(白)
}
[ ]( Exception e ){ // 値がない
bgcolor = Color.white; // デフォルト値(白)
}
setBackground( bgcolor ); // 指定された色を設定
}
}