Applet2.java
import java.applet.Applet;
/** Appletに汎用の機能を追加したApplet2クラス */
public class Applet2 extends Applet {
/** パラメータの文字列をint型に変換するメソッド */
protected int getIntParameter( String word ) throws Exception {
String valueString = getParameter( word );
if( valueString == null ) throw new Exception(); // 例外を発生
return Integer.parseInt( valueString );
}
/** パラメータの文字列をfloat型に変換するメソッド */
protected float getFloatParameter( String word ) throws Exception {
String valueString = getParameter( word );
if( valueString == null ) throw new Exception(); // 例外を発生
return Float.valueOf( valueString ).floatValue();
}
/** パラメータの文字列を 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;
}
}