Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## lejos.nxt
Class Button

    java.lang.Object
      lejos.nxt.Button

All Implemented Interfaces:
  ListenerCaller

    public class Button

extends Object
implements ListenerCaller

Abstraction for an NXT button. Example:

``

        Button.ENTER.waitForPressAndRelease();
        Sound.playTone (1000, 1);

Field Summary
`static Button[]` | `BUTTONS` Array containing ENTER, LEFT, RIGHT, ESCAPE, in that order.
`static Button` | `ENTER` The Enter button.
`static Button` | `ESCAPE` The Escape button.
`static Button` | `LEFT` The Left button.
`static Button` | `RIGHT` The Right button.

Method Summary
`void` | `addButtonListener(ButtonListener aListener)` Adds a listener of button events.
`void` | `callListeners()` Call Button Listeners.
`int` | `getId()` Return the ID of the button.
`boolean` | `isPressed()` Check if the button is pressed.
`static int` | `readButtons()` Low-level API that reads status of buttons.
`void` | `waitForPressAndRelease()` Wait until the button is released.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait`

Field Detail

### ENTER

    public static final Button ENTER

  The Enter button.

### LEFT

    public static final Button LEFT

  The Left button.

### RIGHT

    public static final Button RIGHT

  The Right button.

### ESCAPE

    public static final Button ESCAPE

  The Escape button.

### BUTTONS

    public static final Button[] BUTTONS

  Array containing ENTER, LEFT, RIGHT, ESCAPE, in that order.

Method Detail

### getId

    public final int getId()

  Return the ID of the button. One of 1, 2, 4 or 8.

### isPressed

    public final boolean isPressed()

  Check if the button is pressed.

  Returns:
    `true` if button is pressed, `false` otherwise.

### waitForPressAndRelease

    public final void waitForPressAndRelease()
                                      throws InterruptedException

  Wait until the button is released.

  Throws:
    `InterruptedException`

### addButtonListener

    public void addButtonListener(ButtonListener aListener)

  Adds a listener of button events. Each button can serve at most 4 listeners.

### readButtons

    public static int readButtons()

  Low-level API that reads status of buttons.

  Returns:
    An integer with possibly some bits set: 0x01 (ENTER button pressed) 0x02 (LEFT button pressed), 0x04 (RIGHT button pressed), 0x08 (ESCAPE button pressed). If all buttons are released, this method returns 0.

### callListeners

    public void callListeners()

  Call Button Listeners. Used by ListenerThread.

  Specified by:
    `callListeners` in interface `ListenerCaller`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD