MIC
Pat O'Sullivan
Department of Mathematics and Computer Studies
Mary Immaculate College, Limerick, Ireland

General Information

Student Resources and Information

Interests

Listbox and Buttons in a Window

This project creates a window containing a list box and two buttons.
One of the buttons will cause the turtle to draw whatever shape has been selected in the listbox. The other button will close the window.
We are familiar with the windowcreate and buttoncreate commands.
The listboxcreate command takes fewer inputs. A listbox doesn't have a caption and there are no instructions executed at any stage.
The required inputs in order are:

  1. The name of the parent window,
  2. the name of the list box,
  3. the x-coordinate of the top left hand corner (relative to the top left-hand corner of the parent window),
  4. the y-coordinate of the top left hand corner (relative to the top left-hand corner of the parent window),
  5. the width of the list box,
  6. the height of the listbox.
The command listboxaddstring "liosta [triangle] will add the word "triangle" to the listbox whose name is liosta
The command listboxgetselect "liosta outputs what is currently selected in the listbox whose name is liosta .
The command run listboxgetselect "liosta will run the procedure with the name that is output by listboxgetselect "liosta . This is the command that is executed below when the button with the caption "Draw" is pressed.
I have created a Java driven simulation below.
Type the word lbox into the text box below and press ENTER:

The procedures used are:

to lbox

windowcreate "main "fuinn [Shapes] 0 0 150 150 []     ;Create a window called fuinn.        
                                                                                ;Its title bar will have the word "Shapes" on it.

listboxcreate "fuinn "liosta 50 20 60 30     ;Create a listbox called liosta.        
                                                              ;within the window called "fuinn".
listboxaddstring "liosta [square]     ;Add the word "square" to the listbox.        
listboxaddstring "liosta [triangle]     ;Add the word "triangle" to the listbox.        
listboxaddstring "liosta [pentagon] ;Add the word "pentagon" to the listbox.        

buttoncreate "fuinn "cnaipe1 [Draw] 62 70 30 10 [run listboxgetselect "liosta]  ;Create a button called cnaipe1 within the window
                                                                                "fuinn".        
                                                                                ;This button will run whatever is selected from the listbox.

buttoncreate "fuinn "cnaipe2 [Cancel] 62 110 30 10 [windowdelete "main]

end
to triangle

repeat 3[fd 100 rt 120]

end
to square

repeat 4 [fd 100 rt 90]

end
to pentagon

repeat 5[fd 100 rt 72]

end
 
Department Home
Home
The information found on personal pages should not be considered official material from Mary Immaculate College and the College does not accept any responsibility for its accuracy or otherwise.