ボタン・ウィジェットの追加

ボタン・ウィジェットは、最もシンプルなリッチ・クライアント・ウィジェットであり、他のウィジェットのような状態の維持を必要としません。ボタンの作成と、そのボタンがクリックされた際に実行するイベント・ハンドラーの指定のみを行う必要があります。

  1. コンソール・フォームで、事前定義パーツ consoleButton を使用して、 ボタンを作成します。このパーツが、ボタン・ウィジェットを表わしています。
    Record buttonForm type ConsoleForm {formSize=[12,40]}
        myButton consoleButton 
           {name = "simpleButton", 
            text = "ここをクリック",
            bounds=[4,4,1,15]};
    end
  2. 少なくとも、ボタンについて以下のプロパティーを指定します。
    name
    ボタンをイベント・ハンドラーにリンクするために、後で使用するニーモニック。
    text
    ボタンのラベル。
    bounds
    ボタンの行、列、高さ、幅をそれぞれ表わす、4 個の整数の配列。
  3. openUI ステートメントにおいて、このボタンの PUSHED イベント用の イベント・ハンドラーを指定します。
    onEvent(ConsoleButton.PUSHED : "simpleButton")
        SysLib.writeStderr("You pushed the button.");

この方法でボタンを使用しているコンソール UI プログラムの完全な例を以下に示します。

programs/simpleButton.egl ファイル内:
package programs;

import forms.buttonForm

program simpleButton type BasicProgram 
    
    textValue string;
    counter int=0;
    function main()
        myWindow WINDOW {name="myWindow", 
            position = [1,1]};
        openWindow(myWindow);
        
        myForm buttonForm {};
        displayForm(myForm);
        
        keepGoing boolean = true;
        while (keepGoing == true)
            openUI { bindingByName=no } 
                myForm 
                bind textValue
                OnEvent(ConsoleButton.PUSHED : "simpleButton")
                    counter+=1;
                    textValue = "ボタンのクリックを "
                        +counter+" 回行いました。";
                    SysLib.writeStderr(textValue);
                onEvent(ConsoleButton.PUSHED : "exitButton")
                    keepGoing = false;
            end
        end
    end
    
end
forms/buttonForm.egl ファイル内:
package forms;

record buttonForm type ConsoleForm { formsize=[12,40] }
    introText consoleField 
       {name="introText", 
        position = [1,1], 
        fieldLen = 20};
    myButton consoleButton 
       {name = "simpleButton", 
        text = "ここをクリック",
        bounds=[4,4,1,15]};
    exitButton consoleButton 
       {name = "exitButton", 
        text = "クリックすると終了します",
        bounds=[6,4,1,15]};
end

フィードバック