ParamApplet.java
import java.applet.Applet;
/** Appletに汎用の機能を追加した ParamApplet クラス */
abstract public class ParamApplet extends Applet {
/** パラメータの文字列を int型に変換するメソッド */
protected int getIntParameter(String word) throws Exception {
String valueString = getParameter( word );
if( valueString == null )
throw new Exception(); // 例外が発生
try {
return Integer.parseInt( valueString );
}
catch( NumberFormatException e ){
throw e; // 例外が発生
}
}
/** パラメータの文字列を float型に変換するメソッド */
protected float getFloatParameter(String word) throws Exception {
String valueString = getParameter( word );
if( valueString == null )
throw new Exception(); // 例外が発生
try {
return Float.valueOf( valueString ).floatValue();
}
catch( NumberFormatException e ){
throw e; // 例外が発生
}
}
/** パラメータの文字列を boolean型に変換するメソッド */
protected boolean getBooleanParameter(String word) throws Exception {
String valueString = getParameter( word );
if( valueString == null )
throw new Exception(); // 例外が発生
if( valueString.equals( "true" ) ) return true;
else return false;
}
}