Anders als das Schaltflächenwidget besitzt das Kontrollkästchenwidget einen Status, denn es ist entweder ausgewählt oder abgewählt. Daher müssen Sie eine boolesche Variable an das Kontrollkästchen binden. Dies ist mit dem Binden einer Textvariablen an ein Textfeld in einem Konsolenformular vergleichbar. Wenn der Benutzer das Kontrollkästchen auswählt, wird die Variable auf TRUE gesetzt. Wählt der Benutzer das Kontrollkästchen ab, wird die Variable auf FALSE gesetzt.
Record checkForm type ConsoleForm {formSize=[12,40]}
myCheck consoleCheckbox
{name = "simpleCheck",
text = "Click here",
bounds=[4,4,1,15]};
end
checkState boolean = false;
myForm checkForm {};
openUI myForm
bind checkState
//event handlers go here
end
onEvent(ConsoleCheckbox.STATE_CHANGED : "simpleCheck")
if (checkState == true)
SysLib.writeStderr("Checked");
else
SysLib.writeStderr("Cleared");
end
Nachfolgend ist ein umfassendes Beispiel für ein Programm der Konsolenbenutzerschnittstelle dargestellt, das ein Kontrollkästchen auf diese Weise verwendet.
package programs;
import forms.checkForm;
program simpleCheckbox type BasicProgram
function main()
myWindow WINDOW {name="myWindow", position = [1,1]};
openWindow(myWindow);
myForm checkForm {};
displayForm(myForm);
textValue string = "Text.";
keepGoing boolean = true;
myCheckVar boolean = false;
while (keepGoing == true)
openUI myForm
bind textValue, myCheckVar
onEvent(ConsoleButton.PUSHED : "exitButton")
keepGoing = false;
onEvent(ConsoleCheckbox.STATE_CHANGED : "simpleCheck")
if (myCheckVar == true)
textValue = "Checked";
else
textValue = "Cleared";
end
end
end
end
end
package forms;
record checkForm type ConsoleForm { formsize=[12,40] }
introText consoleField
{name="introText",
position = [1,1],
fieldLen = 20};
myCheck consoleCheckbox
{name="simpleCheck",
text="Checkbox",
bounds=[3,5,1,15]};
exitButton consoleButton
{name = "exitButton",
text = "Click to exit",
bounds=[6,4,1,15]};
end