TEJ 3M Buttons Name: Syntax to Create a Button: GUI.CreateButton (x, y, width, text, actionProc) x, y - the x and y parameters specify the lower-left corner of the button width - width of the button text - the text that will appear on the button actionProc - is the name of the procedure that is run when the button is pressed GUI.CreateButtonFull (x, y, width, text, actionProc, height, shortcut, default) x, y - the x and y parameters specify the lower-left corner of the button width - width of the button text - the text that will appear on the button actionProc - is the name of the procedure that is run when the button is pressed height - less than the size necessary to display the button, the button is automatically enlarged to fit the text shortcut - the keystroke to be used as the button's shortcut default - is a boolean indicating whether the button should be the default button (The two possible Boolean values are true and false) Example 1: Creating a Button %The following program creates two buttons, one which draws a random circle on the screen and one which quits %the program. import GUI procedure DrawRandomCircle var r : int := Rand.Int (20, 50) var x : int := Rand.Int (r, maxx) var y : int := Rand.Int (r, maxy) var c : int := Rand.Int (0, maxcolor) Draw.FillOval (x, y, r, r, c) % In case we drew over the buttons, redraw them. GUI.Refresh end DrawRandomCircle View.Set ("graphics:300;200,nobuttonbar ") var draw : int := GUI.CreateButtonFull (50, 10, 0, "Draw Circle", DrawRandomCircle, 0, '^D', true) var quitBtn : int := GUI.CreateButton (200, 10, 0, "Quit", GUI.Quit) loop exit when GUI.ProcessEvent end loop Check Boxes: Syntax to Create a Check Boxes: GUI.CreateCheckBox (x, y, text, actionProc:procedure x (filled : boolean)) x, y - the x and y parameters specify the lower-left corner of the button width - width of the button text - the text that will appear on the button actionProc - is the name of the procedure that is run when the button is pressed GUI.CreateCheckBoxFull (x, y, text, actionProc:procedure x (filled : boolean), alignment, shortcut) x, y - the x and y parameters specify the lower-left corner of the button text - the text that will appear on the button actionProc - is the name of the procedure that is run when the button is pressed alignment - specifies the position of the check box in relation to the text as well as the meaning of the x and y parameters shortcut - the keystroke to be used as the button's shortcut %The following program creates two buttons, one which draws a random circle on the screen and one which quits % the program import GUI procedure DoNothing (status : boolean) %as title this procedure does nothing end DoNothing View.Set ("graphics:300;100,nobuttonbar") var cb1, cb2, quitBtn : int cb1 := GUI.CreateCheckBox (10, 10, "Check Box 1", DoNothing) cb2 := GUI.CreateCheckBoxFull (200, 10, "Check Box 2", DoNothing, GUI.RIGHT, '2') %2 at end is shortcut key GUI.SetCheckBox (cb2, true) %sets the button called cb2 to be checked off to start quitBtn := GUI.CreateButton (230, 10, 0, "Quit", GUI.Quit) %creates a quit button labled 'Quit' loop exit when GUI.ProcessEvent end loop var cb1Status, cb2Status : Boolean cb1Status := GUI.GetCheckBox (cb1) cb2Status := GUI.GetCheckBox (cb2) if cb1Status then put "Check box 1: filled" else put "Check box 1: empty" end if if cb2Status then put "Check box 2: filled" else put "Check box 2: empty" end if Radio Buttons: Syntax to Create a Radio Button: GUI.CreateRadioButton (x, y, text, joinID, actionProc) x, y - the x and y parameters specify the lower-left corner of the button text - the text that will appear on the button joinID - specifies the group the radio button belongs to actionProc - is the name of the procedure that is run when the button is pressed GUI.CreateRadioButtonFull (x, y, text, joinID, actionProc, alignment, shortCut) x, y - the x and y parameters specify the lower-left corner of the button text - the text that will appear on the button joinID - specifies the group the radio button belongs to actionProc - is the name of the procedure that is run when the button is pressed alignment - specifies the position of the radio button in relation to the text as well as the meaning of the x and y parameters shortcut - the keystroke to be used as the button's shortcut Alignment Parameter Options: The alignment parameter is one of 0, GUI.LEFT, or GUI.RIGHT. An alignment of 0 is the default and is the same as GUI.LEFT. GUI.LEFT means the actual box in the check box appears to the left of the check box's label and (x, y) specify the lower-left corner. An alignment of GUI.RIGHT means that the actual box appears to the right of the radio button's label and (x, y) specify the lower-right corner of the radio button. Example Create Radio Button %The following program creates six radio buttons in two groups. import GUI View.Set ("graphics:350;80") var radio : array 1 .. 6 of int % The radio button IDs. procedure RadioPressed Text.Locate (1, 1) put "Radio Button " .. for i : 1 .. 6 if radio (i) = GUI.GetEventWidgetID then put i .. end if end for put " Selected" end RadioPressed radio (1) := GUI.CreateRadioButton (1, 35, "Radio Button 1", 0, RadioPressed) radio (2) := GUI.CreateRadioButton ( 1, 20, "Radio Button 2", radio (1), RadioPressed) radio (3) := GUI.CreateRadioButton ( 1, 5, "Radio Button 3",radio (2), RadioPressed) radio (4) := GUI.CreateRadioButtonFull (maxx - 15, 35, "Radio Button A (Shortcut: 'a')", 0, RadioPressed, GUI.RIGHT, 'a') radio (5) := GUI.CreateRadioButtonFull (maxx - 15, 20, "Radio Button B (Shortcut: 'b')", radio (4), RadioPressed, GUI.RIGHT, 'b') radio (6) := GUI.CreateRadioButtonFull (maxx - 15, 5, "Radio Button C (Shortcut: 'c')", radio (5), RadioPressed, GUI.RIGHT, 'c') loop exit when GUI.ProcessEvent end loop