Example usage for java.awt Menu addActionListener

List of usage examples for java.awt Menu addActionListener

Introduction

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

Prototype

public synchronized void addActionListener(ActionListener l) 

Source Link

Document

Adds the specified action listener to receive action events from this menu item.

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  .  j  a va 2 s .c  om*/
 * @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;
}