ActionTest.java
import java.awt.*;
import java.applet.Applet;
/** アクションの処理をテストするアプレット ActionTest クラス */
public class ActionTest extends Applet {
/** インターフェイスの部品の宣言 */
public Button redButton, greenButton, blueButton;
/** 初期設定のメソッド */
public void init() {
redButton = new Button( "Red" );
redButton.setBackground( Color.red );
add( redButton );
greenButton = new Button( "Green" );
greenButton.setBackground( Color.green );
add( greenButton );
blueButton = new Button( "Blue" );
blueButton.setBackground( Color.blue );
add( blueButton );
}
/** アクションの処理のメソッド */
public boolean action( Event evt, Object obj ) {
String name = obj.toString(); // アクションの対象を調べる
if( name.equals("Red") ) {
setBackground( Color.red );
}
else if( name.equals("Green") ) {
setBackground( Color.green );
}
else if( name.equals("Blue") ) {
setBackground( Color.blue );
}
redButton.setBackground( Color.red );
greenButton.setBackground( Color.green );
blueButton.setBackground( Color.blue );
return true;
}
}