Das Schaltflächenwidget ist das einfachste Rich-Client-Widget, weil es im Gegensatz zu den anderen Widgets keinen Status verwalten muss. Sie müssen lediglich die Schaltfläche erstellen und einen Ereignishandler angeben, der ausgeführt werden soll, wenn auf die Schaltfläche geklickt wird.
Record buttonForm type ConsoleForm {formSize=[12,40]}
myButton consoleButton
{name = "simpleButton",
text = "Click here",
bounds=[4,4,1,15]};
end
onEvent(ConsoleButton.PUSHED : "simpleButton")
SysLib.writeStderr("Sie haben die Schaltfläche ausgewählt.");
Nachfolgend ist ein umfassendes Beispiel für ein Programm der Konsolenbenutzerschnittstelle dargestellt, das eine Schaltfläche auf diese Weise verwendet.
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 = "You have clicked the button "
+counter+" times.";
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 = "Click here",
bounds=[4,4,1,15]};
exitButton consoleButton
{name = "exitButton",
text = "Click to exit",
bounds=[6,4,1,15]};
end