import java.awt.*; 

public class ButtonFrame extends Frame {

    public boolean action(Event evt, Object obj) {
        String label = obj.toString();
    
        if(evt.target instanceof Button) {
            if(label.equals("On")) 
                System.out.println("Pushed button is On.");
            else
                System.out.println("Pushed button is Off.");
        }
        else {
            System.out.println("Not a Button event.");
        }
        return true;
    }
    
    public boolean handleEvent(Event evt) {
        if(evt.id == Event.WINDOW_DESTROY) {  // ウインドウの破棄
            dispose();      // 資源の解放
            System.exit(0); // プログラムの終了
            return true;
        }
        else {
            return super.handleEvent(evt);  // 処理しないイベントはsuperへ
        }
    }

    public static void main(String args[]) {
        ButtonFrame bf = new ButtonFrame();
        bf.resize(200,150);  // サイズの設定

        Panel pnl = new Panel();  // パネルの生成
        pnl.setFont(new Font("Helvetica", Font.BOLD, 24));
        pnl.add(new Button("On"));   // "on"ボタンの作成と追加
        pnl.add(new Button("Off"));  // "off"ボタンの作成と追加
        
        bf.add(pnl);  // パネルのフレームへの追加
        bf.show();  // フレームの可視化
    }
} 
