View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007


The comment section in Squeak for this class is also helpful. The world menu that appears when you do a left click on the main screen in Squeak is a MenuMorph. Each item in the menu is a MenuItemMorph. MenuItemMorph is not called directly though. The itmes are manipulated via the MenuMorph. The code below should provide some guidance.

Its also worth noting that drop down menu's like 'File' and 'Edit' in the Windows OS don't exist. The closest implementation to them in Squeak is to use a PluggableButtonMorph and have the button when clicked call a method that implements the code:
myMenu popUpInWorld: self world.

The menu will pop up right where the button was clicked mimicking a JMenu or a Windows based 'File' menu.

Useful Code

Creates a menu that has the options of creating a person or creating a room. The create person option is tied to the method createPerson which is contained in the class that has myMenu. The create room option is not tied to any method and consequently will do nothing when it is clicked. It can be tied to a method at a later point in the program.
myMenu = MenuMorph entitled: 'My Menu'.
myMenu add: 'Create Person' target: self action: #createPerson;
      add: 'Create Room' action: nil.

Gives the second option of myMenu a submenu. To get rid of the submenu call subMenu: and pass it nil for its argument Also, disables the first option of myMenu.
(myMenu items at: 2) subMenu: anotherMenu.
(myMenu items at: 1) isEnabled: false.

Sets the method a MenuItem should be tied to after the menuItem has been instantiated.
(myMenu items at: 2) target: self; selector: #saveGame.

Link to this Page