Help: Menus


Help is available for each task, or you can go straight to the solution source code.

Task 1

Create an applet called MenuTest. Add a Frame bean to the applet and connect the applet's componentShown method to the frame's show method.

Also add a TextField bean to the frame.


To make the connection, left-click on the applet, select Connect->All features... and select Event->componentShown(java.awt.ComponentEvent) in the dialog box that appears; click OK.

Now move your mouse to the Frame, click then select show().

Task 2

Add a MenuBar bean to the frame with two menus:
  1. File should contain:
    1. Open
    2. Close
    3. Exit
  2. Help should contain:
    1. Fundamentals
    2. Advanced
    3. - (a separator)
    4. Have Read The Manual (as a CheckboxMenuItem)
    5. Have Read The Tutorial (as a CheckboxMenuItem)
    6. Misc (submenu) with:
      1. Sub-item 1
      2. Sub-item 2

To add the menus to the menubar, drop the Menu bean onto the the menubar contained within the frame.

To add menu-items to the menus, drop the MenuItem beans onto the gray windows representing the menus.

To add a sub-menu, drop a MenuBar bean onto the Help window.

Task 3

For each MenuItem and CheckBoxMenuItem, create a connection such that a user selecting the menu-item causes the textfield to display the menu-item's label.
To complete this task you actually need to create two connections for each menu-item:
  1. An event-to-method connection between the menu-item's actionPerformedEvent and the textfield's text method.
  2. A property-to-property connection between the above connection's value property and the label property of the menu-item.

    For the CheckboxMenuItems, connect the itemStateChanged (instead of the actionPerformedEvent) event to the text method of the textfield.


Copyright © 1996-1997 MageLang Institute. All Rights Reserved.