ボタン・ウィジェットは、最もシンプルなリッチ・クライアント・ウィジェットであり、他のウィジェットのような状態の維持を必要としません。ボタンの作成と、そのボタンがクリックされた際に実行するイベント・ハンドラーの指定のみを行う必要があります。
Record buttonForm type ConsoleForm {formSize=[12,40]}
myButton consoleButton
{name = "simpleButton",
text = "ここをクリック",
bounds=[4,4,1,15]};
end
onEvent(ConsoleButton.PUSHED : "simpleButton")
SysLib.writeStderr("You pushed the button.");
この方法でボタンを使用しているコンソール UI プログラムの完全な例を以下に示します。
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
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