Explain creation of menu bar, menu, and menu items with suitable java code segment.

 MENUBARS

A top-level window can have a menu bar associated with it. A menu bar displays a list of top level menu choices. Each choice is associated with a drop-down menu.

Commonly used Constructors of MenuBar Class

MenuBar(); //Creates a new menu bar.

Commonly used Public Methods of MenuBar Class

Menu add(Menu m); //Adds the specified menu to the menu bar.

Menu getMenu(int i); //Gets the specified menu. (an

int getMenuCount(); //Gets the number of menus on the menu bar.

void remove(int index); //Removes the menu located at the specified index from this menu bar.

void remove(MenuComponent m); //Removes the specified menu component from this menu bar.


Menu Class

The Menu class represents the pull-down menu component that is deployed from a menu bar. We can create a hierarchy of submenus within a menu.

Commonly used Constructors of Menu Class

Menu(); //Constructs a new menu with an empty label.

Menu(String label); //Constructs a new menu with the specified label.

 Menu(String label, boolean tear of); //Constructs a new menu with the specified label, indicating whether the menu can be torn off.

Commonly used Public Methods of Menu Class

Menultem add(Menultem mi); //Adds the specified menu item to this menu. void addSeparator(); //Adds a separator line, or a hyphen, to the menu at the current position.

Menultem getItem(int index); //Gets the item located at the specified index of this menu. 

int getItemCount(); //Get the number of items in this menu. 

void insert(MenuItem menuitem, int index); //Inserts a menu item into this menu at the specified position.

void insertSeparator(int index); //Inserts a separator at the specified position.

void remove(int index); //Removes the menu item at the specified index from this menu.

void remove(MenuComponent item); //Removes the specified menu item from this menu.

void removeAll(); //Removes all items from this menu.


MenuItem Class

All items in a menu should derive from class Menultem or one of its subclasses. By default, it embodies a simple labeled menu item.

Commonly used Constructors of Menultem Class

MenuItem(); //Constructs a new MenuItem with an empty label and no keyboard shortcut. MenuItem(String label); //Constructs a new Menultem with the specified label and no keyboard shortcut.

MenuItem(String label, MenuShortcut s); //Create a menu item with an associated keyboard shortcut.

Commonly used Public Methods of Menultem Class

void deleteShortcut(); //Delete any MenuShortcut object associated with this menu item.

String getAction Command(); //Gets the command name of the action event that is fired by this menu item.

                      OR

Java AWT MenuItem and Menu

The object of MenuItem class adds a simple labeled menu item on the menu. The items used in a menu must belong to the MenuItem or any of its subclass.

The object of the Menu class is a pull-down menu component that is displayed on the menu bar. It inherits the MenuItem class.


AWT MenuItem class declaration

public class MenuItem extends MenuComponent implements Accessible  

AWT Menu class declaration

public class Menu extends MenuItem implements MenuContainer, Accessible  

Java AWT MenuItem and Menu Example

import java.awt.*;  

class MenuExample  

{  

     MenuExample(){  

         Frame f= new Frame("Menu and MenuItem Example");  

         MenuBar mb=new MenuBar();  

         Menu menu=new Menu("Menu");  

         Menu submenu=new Menu("Sub Menu");  

         MenuItem i1=new MenuItem("Item 1");  

         MenuItem i2=new MenuItem("Item 2");  

         MenuItem i3=new MenuItem("Item 3");  

         MenuItem i4=new MenuItem("Item 4");  

         MenuItem i5=new MenuItem("Item 5");  

         menu.add(i1);  

         menu.add(i2);  

         menu.add(i3);  

         submenu.add(i4);  

         submenu.add(i5);  

         menu.add(submenu);  

         mb.add(menu);  

         f.setMenuBar(mb);  

         f.setSize(400,400);  

         f.setLayout(null);  

         f.setVisible(true);  

}  

public static void main(String args[])  

{  

new MenuExample();  

}  

}  

Output:



Comments

Popular posts from this blog

Suppose that a data warehouse for Big-University consists of the following four dimensions: student, course, semester, and instructor, and two measures count and avg_grade. When at the lowest conceptual level (e.g., for a given student, course, semester, and instructor combination), the avg_grade measure stores the actual course grade of the student. At higher conceptual levels, avg_grade stores the average grade for the given combination. a) Draw a snowflake schema diagram for the data warehouse. b) Starting with the base cuboid [student, course, semester, instructor], what specific OLAP operations (e.g., roll-up from semester to year) should one perform in order to list the average grade of CS courses for each BigUniversity student. c) If each dimension has five levels (including all), such as “student < major < status < university < all”, how many cuboids will this cube contain (including the base and apex cuboids)?

Suppose that a data warehouse consists of the three dimensions time, doctor, and patient, and the two measures count and charge, where a charge is the fee that a doctor charges a patient for a visit. a) Draw a schema diagram for the above data warehouse using one of the schemas. [star, snowflake, fact constellation] b) Starting with the base cuboid [day, doctor, patient], what specific OLAP operations should be performed in order to list the total fee collected by each doctor in 2004? c) To obtain the same list, write an SQL query assuming the data are stored in a relational database with the schema fee (day, month, year, doctor, hospital, patient, count, charge)

Suppose that a data warehouse consists of the four dimensions; date, spectator, location, and game, and the two measures, count and charge, where charge is the fee that a spectator pays when watching a game on a given date. Spectators may be students, adults, or seniors, with each category having its own charge rate. a) Draw a star schema diagram for the data b) Starting with the base cuboid [date; spectator; location; game], what specific OLAP operations should perform in order to list the total charge paid by student spectators at GM Place in 2004?