Example usage for java.awt Menu Menu

List of usage examples for java.awt Menu Menu

Introduction

In this page you can find the example usage for java.awt Menu Menu.

Prototype

public Menu(String label) throws HeadlessException 

Source Link

Document

Constructs a new menu with the specified label.

Usage

From source file:ExText.java

/**
 * Builds the example AWT Frame menubar. Standard menus and their options
 * are added. Applications that subclass this class should build their
 * menubar additions within their initialize method.
 * //ww w. ja va2 s . com
 * @return a MenuBar for the AWT Frame
 */
private MenuBar buildMenuBar() {
    // Build the menubar
    MenuBar menuBar = new MenuBar();

    // File menu
    Menu m = new Menu("File");
    m.addActionListener(this);

    m.add("Exit");

    menuBar.add(m);

    // View menu
    m = new Menu("View");
    m.addActionListener(this);

    m.add("Reset view");

    m.addSeparator();

    walkMenuItem = new CheckboxMenuItem("Walk");
    walkMenuItem.addItemListener(this);
    m.add(walkMenuItem);

    examineMenuItem = new CheckboxMenuItem("Examine");
    examineMenuItem.addItemListener(this);
    m.add(examineMenuItem);

    if (navigationType == Walk) {
        walkMenuItem.setState(true);
        examineMenuItem.setState(false);
    } else {
        walkMenuItem.setState(false);
        examineMenuItem.setState(true);
    }

    m.addSeparator();

    headlightMenuItem = new CheckboxMenuItem("Headlight on/off");
    headlightMenuItem.addItemListener(this);
    headlightMenuItem.setState(headlightOnOff);
    m.add(headlightMenuItem);

    menuBar.add(m);

    return menuBar;
}

From source file:AppearanceTest.java

public Menu createMenu() {
    String szName = getName();/*  ww  w  .  ja  v a 2  s  .  com*/
    String[] itemArray = getMenuItemNames();
    ActionListener listener = this;

    Menu menu = new Menu(szName);

    MenuItem menuItem = new MenuItem("Null");
    menuItem.addActionListener(listener);
    menu.add(menuItem);

    menuItem = new MenuItem("Non_Null");
    menuItem.addActionListener(listener);
    menu.add(menuItem);

    for (int n = 0; n < itemArray.length; n++) {
        menuItem = new MenuItem(itemArray[n]);
        menuItem.addActionListener(listener);
        menu.add(menuItem);
    }

    return menu;
}

From source file:org.rapidcontext.app.ui.ControlPanel.java

/**
 * Initializes the frame menu./*from ww  w. j a va 2s  . c om*/
 */
private void initializeMenu() {
    Menu menu;
    MenuItem item;

    // Create file menu
    if (!SystemUtils.IS_OS_MAC_OSX) {
        menu = new Menu("File");
        item = new MenuItem("Exit", new MenuShortcut(KeyEvent.VK_Q));
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                quit();
            }
        });
        menu.add(item);
        menuBar.add(menu);
        menu = new Menu("Help");
        item = new MenuItem("About");
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                about();
            }
        });
        menu.add(item);
        menuBar.add(menu);
    }

    // Fix Mac OS specific menus
    if (SystemUtils.IS_OS_MAC_OSX) {
        try {
            MacApplication.get().setAboutHandler(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    about();
                }
            });
            MacApplication.get().setPreferencesHandler(null);
        } catch (Exception ignore) {
            // Errors are ignored
        }
    }
}