|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object lejos.nxt.Button
public class Button
Abstraction for an NXT button. Example:
Button.ENTER.waitForPressAndRelease(); Sound.playTone (1000, 1);Notions: The API is designed around two notions: states (up / down) and events (press / release). It is said that a button is pressed (press event), if its state changes from up to down. Similarly, it is said that a button is released (release event), if its states changed from down to up. Thread Safety: All methods that return buttons states can be used safely from multiple threads, even while a call to one of the waitFor* methods active. However, it is not safe to invoke waitFor* methods in parallel from different threads. This includes the waitFor* methods of different buttons. For example Button.ENTER.waitForPress() must not be invoked in parallel to Button.ESCAPE.waitForPress() or the static Button.waitForAnyEvent(). In case this is needed, it is strongly recommended that you write your own Thread, which waits for button events and dispatches the events to anyone who's interested.
Field Summary | |
---|---|
static Button[] |
BUTTONS
Deprecated. this array will be removed |
static Button |
ENTER
The Enter button. |
static Button |
ESCAPE
The Escape button. |
static int |
ID_ENTER
|
static int |
ID_ESCAPE
|
static int |
ID_LEFT
|
static int |
ID_RIGHT
|
static Button |
LEFT
The Left button. |
static Button |
RIGHT
The Right button. |
static String |
VOL_SETTING
|
Method Summary | |
---|---|
void |
addButtonListener(ButtonListener aListener)
Adds a listener of button events. |
int |
callListeners()
Call Button Listeners. |
static void |
discardEvents()
This method discards and events. |
int |
getId()
Return the ID of the button. |
static int |
getKeyClickLength()
Return the current key click length. |
static int |
getKeyClickTone(int key)
Return the click freq for a particular key. |
static int |
getKeyClickVolume()
Return the current key click volume. |
boolean |
isDown()
Check if the current state of the button is down. |
boolean |
isPressed()
Deprecated. use isDown() instead. |
boolean |
isUp()
Check if the current state of the button is up. |
static void |
loadSettings()
Deprecated. replaced by loadSystemSettings() . |
static void |
loadSystemSettings()
Load the current system settings associated with this class. |
static int |
readButtons()
Low-level API that reads status of buttons. |
static void |
setKeyClickLength(int len)
Set the len used for key clicks |
static void |
setKeyClickTone(int key,
int freq)
Set the frequency used for a particular key. |
static void |
setKeyClickVolume(int vol)
Set the volume used for key clicks |
static int |
waitForAnyEvent(int timeout)
Waits for some button to be pressed or released. |
static int |
waitForAnyPress()
Waits for some button to be pressed. |
static int |
waitForAnyPress(int timeout)
Waits for some button to be pressed. |
void |
waitForPress()
Wait until the button is released. |
void |
waitForPressAndRelease()
Wait until the button is released. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int ID_ENTER
public static final int ID_LEFT
public static final int ID_RIGHT
public static final int ID_ESCAPE
public static final String VOL_SETTING
public static final Button ENTER
public static final Button LEFT
public static final Button RIGHT
public static final Button ESCAPE
@Deprecated public static final Button[] BUTTONS
Method Detail |
---|
public final int getId()
@Deprecated public final boolean isPressed()
isDown()
instead.
public final boolean isDown()
true
if button is down, false
if up.public final boolean isUp()
true
if button is down, false
if up.public final void waitForPress()
public final void waitForPressAndRelease()
public static void discardEvents()
readButtons()
, this method doesn't beep if a button is pressed.
public static int waitForAnyEvent(int timeout)
timeout
- The maximum number of milliseconds to wait
ID_ENTER
,
ID_LEFT
,
ID_RIGHT
,
ID_ESCAPE
public static int waitForAnyPress(int timeout)
timeout
- The maximum number of milliseconds to wait
public static int waitForAnyPress()
public void addButtonListener(ButtonListener aListener)
aListener
- The new listenerpublic static int readButtons()
ID_ENTER
(ENTER
button pressed) ID_LEFT
(LEFT button pressed),
ID_RIGHT
(RIGHT button pressed), ID_ESCAPE
(ESCAPE button pressed). If all buttons are released, this method
returns 0.public int callListeners()
callListeners
in interface ListenerCaller
public static void setKeyClickVolume(int vol)
vol
- public static int getKeyClickVolume()
public static void setKeyClickLength(int len)
len
- the click durationpublic static int getKeyClickLength()
public static void setKeyClickTone(int key, int freq)
key
- the NXT keyfreq
- the frequencypublic static int getKeyClickTone(int key)
key
- The key to obtain the tone for
@Deprecated public static void loadSettings()
loadSystemSettings()
.
public static void loadSystemSettings()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |