import java.awt.*;
import java.applet.Applet;

/**
 他のコンポーネントの表示をコントロールする ShowControl クラス
 */
class ShowControl extends Checkbox {

   /**
     コントロールを受けるコンポーネント
    */
      Component sheep;

   /**
     コンストラクタ
    */
      ShowControl( String label, Component sheep ) {
           super(label);
           this.sheep = sheep;
      }

   /**
     独自のアクション処理
    */
      public boolean action( Event evt, Object obj ) {

            if( getState() ) sheep.hide();
            else             sheep.show();

            return true;
      }
}

/**
 他のコンポーネントの状態をコントロールする EnableControl クラス
 */
class EnableControl extends Checkbox {

   /**
     コントロールを受けるコンポーネント
    */
      Component sheep;

   /**
     コンストラクタ
    */
      EnableControl( String label, Component sheep ) {
           super(label);
           this.sheep = sheep;
      }

   /**
     独自のアクション処理
    */
      public boolean action( Event evt, Object obj ) {

            if( getState() ) sheep.disable();
            else             sheep.enable();

            return true;
      }
}

/**
 アクションの処理をテストするアプレット ButtonControl クラス
 */
public class ButtonControl extends Applet {

   /**
     インターフェイスの部品の宣言
    */ 
      public Button button;
      public ShowControl showControl;
      public EnableControl enableControl;

   /**
     初期設定の関数
    */
      public void init() {

           button = new Button( "I am Controled by Anyone." );
           showControl = new ShowControl( "Show/Hide", button );
           enableControl = new EnableControl( "Enable/Disable", showControl );
           add( enableControl );
           add( showControl );
           add( button );
      }
}

