Page 2 :
1.4 Use of Layout Managers:, , , Menu Bars and Menus:, , , , A top-level window can have a menubar associated with, it., , , , A menubar displays a list of top-level menu choices., Each choice is associated with a drop- down menu., , , , This concept is implemented in Java by the following, andMenuItem., classes: MenuBar, Menu, and, MenuItem., , DJ Sir
Page 3 :
1.4 Use of Layout Managers:, , , Menu Bars and Menus:, , , , In general, a menubar contains one or more Menu, objects., , , , Each Menu object contains a list of MenuItem objects., , , , Each MenuItem object represents something that can be, selected by the user., , DJ Sir
Page 4 :
1.4 Use of Layout Managers:, , , Menu Bars and Menus:, , , , Since Menu is a subclass of MenuItem, a hierarchy of, nested submenus can be created., , , , It is also possible to include checkable menu items., These are menu options of type CheckboxMenuItem and, will have a check mark next to them when they are, selected., , DJ Sir
Page 5 :
1.4 Use of Layout Managers:, , , Menu Bars and Menus:, , , , For creating a menubar, we first create an instance of, MenuBar., , , , This class only defines the default constructor., , , , Next, create instances of Menu that will define the, selections displayed on the bar., , DJ Sir
Page 6 :
1.4 Use of Layout Managers:, , , Menu Bars and Menus:, , Create, MenuBar, Object, , DJ Sir, , Add, , Menu, Objects, , Add, MenuItems to, Menu, , Add, MenuBar to, Frame
Page 7 :
1.4 Use of Layout Managers:, , , Menu Bars and Menus: Constructors, , , , Menu( ), , , , Menu(String optionName), , , , Menu(String optionName, boolean removable), , , , Here, optionName specifies the name of the menu, selection., , DJ Sir
Page 8 :
1.4 Use of Layout Managers:, , , Menu Bars and Menus: Constructors, , , , If removable is true, the pop-up menu can be removed, and allowed to float free., , , , Otherwise, it will remain attached to the menu bar., (Removable menus are implementation-dependent.), The first form creates an empty menu., , DJ Sir
Page 10 :
1.4 Use of Layout Managers:, , , Menu Bars and Menus: Constructors, , , , Here,itemName is the name shown in the menu, and, keyAccel is the menu shortcut for this item., , DJ Sir
Page 11 :
1.4 Use of Layout Managers:, , , Menu Bars and Menus: Methods, , , , We can disable or enable a menu item by using the, setEnabled( ) method., void setEnabled(boolean enabledFlag), , , , If the argument enabledFlag is true,the menu item is, enabled. If false, the menuitem is disabled., , DJ Sir
Page 12 :
1.4 Use of Layout Managers:, , , Menu Bars and Menus: Methods, , , , We can determine an item’s status by calling isEnabled()., boolean isEnabled( ), , , , The isEnabled() returns true if the menuitem on which it, is called is enabled. Otherwise,it returns false., , , , We can change the name of a menuitem by calling, setLabel()., , DJ Sir
Page 13 :
1.4 Use of Layout Managers:, , , Menu Bars and Menus: Methods, , , , We can retrieve the current name by using getLabel()., void setLabel(String newName), String getLabel( ), , , , Here, newName becomes the new name of the invoking, menu item. getLabel() returns the current name., , DJ Sir
Page 15 :
1.4 Use of Layout Managers:, , , Menu Bars and Menus: Methods, , , , Here, itemName is the name shown in the menu., , , , Checkable items operate as toggles., , , , Each time one is selected,its state changes. In the first, two forms,the checkable entry is unchecked., , , , Inthe, thethird, thirdform,ifonistrue,the, form,if on is true,the, checkable, is, In, checkable, entry isentry, initially, initially, Otherwise,, it is cleared., checked.checked., Otherwise,, it is cleared., , DJ Sir
Page 17 :
1.4 Use of Layout Managers:, , , Menu Bars and Menus: Methods, , , , If the item is checked, getState() returns true. Otherwise,, it returns false., , , , For checking an item,pass true to setState().To clear an, item,pass false., , DJ Sir
Page 18 :
1.4 Use of Layout Managers:, , , Menu Bars and Menus: Methods, , , , Once we have created a menu item, we must add the item, to a Menu object by using add( ),, MenuItem add(MenuItem item), , , , Here,item is the item being added.Items are added to a, menu in the order in which the calls to add() take, takeplace., place.The, is returned., The item isitem, returned, , DJ Sir
Page 19 :
1.4 Use of Layout Managers:, , , Menu Bars and Menus: Methods, , , , Once we have added all items to a Menu object,we can, add that object to the menubar by using this version of, add( ) defined by MenuBar:, Menu add(Menu menu), , , , Here,menu is the menu being added., , DJ Sir
Page 20 :
1.4 Use of Layout Managers:, , , Menu Bars and Menus :Example, , DJ Sir