jplay
Class Keyboard

java.lang.Object
  extended by jplay.InputBase
      extended by jplay.Keyboard
All Implemented Interfaces:
java.awt.event.KeyListener, java.util.EventListener

public final class Keyboard
extends InputBase
implements java.awt.event.KeyListener

Class responsible for handling the keys of keyboard and its behavior.


Field Summary
static int DOWN_KEY
          The direction key for under of the keyboard.
static int ENTER_KEY
          The enter key of the keyboard.
static int ESCAPE_KEY
          The ESC key of the keyboard.
static int LEFT_KEY
          The direction key for left of the keyboard.
static int RIGHT_KEY
          The direction key for right of the keyboard.
static int SPACE_KEY
          The space bar of the keyboard.
static int UP_KEY
          The direction key for above of the keyboard.
 
Fields inherited from class jplay.InputBase
DETECT_EVERY_PRESS, DETECT_INITIAL_PRESS_ONLY
 
Constructor Summary
Keyboard()
          Create instance of class Keyboard with the following keys and its behavior: UP_KEY, LEFT_KEY, RIGHT_KEY, DOWN_KEY have the behavior DETECT_EVERY_PRESS, and the keys ESCAPE_KEY, SPACE_KEY, ENTER_KEY have the behavior DETECT_INITIAL_PRESS_ONLY.
 
Method Summary
 void addKey(int key)
          Overloading the method void addKey(int key, int behavior), the behavior will be DETECT_INITAL_PRESS_ONLY.
 void addKey(int key, int behavior)
          Method used for adding a key to an instance of the keyboard and its behavior.
 boolean keyDown(int key)
          Method used for knowing if a key is pressed.
 void keyPressed(java.awt.event.KeyEvent e)
           
 void keyReleased(java.awt.event.KeyEvent e)
           
 void keyTyped(java.awt.event.KeyEvent e)
           
 void removeKey(int key)
          Remove a key of the instance of the keyboard.
 void setBehavior(int key, int behavior)
          Set a new behavior for a key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UP_KEY

public static final int UP_KEY
The direction key for above of the keyboard.

See Also:
Constant Field Values

LEFT_KEY

public static final int LEFT_KEY
The direction key for left of the keyboard.

See Also:
Constant Field Values

RIGHT_KEY

public static final int RIGHT_KEY
The direction key for right of the keyboard.

See Also:
Constant Field Values

DOWN_KEY

public static final int DOWN_KEY
The direction key for under of the keyboard.

See Also:
Constant Field Values

ESCAPE_KEY

public static final int ESCAPE_KEY
The ESC key of the keyboard.

See Also:
Constant Field Values

SPACE_KEY

public static final int SPACE_KEY
The space bar of the keyboard.

See Also:
Constant Field Values

ENTER_KEY

public static final int ENTER_KEY
The enter key of the keyboard.

See Also:
Constant Field Values
Constructor Detail

Keyboard

public Keyboard()
Create instance of class Keyboard with the following keys and its behavior: UP_KEY, LEFT_KEY, RIGHT_KEY, DOWN_KEY have the behavior DETECT_EVERY_PRESS, and the keys ESCAPE_KEY, SPACE_KEY, ENTER_KEY have the behavior DETECT_INITIAL_PRESS_ONLY.

Method Detail

keyDown

public boolean keyDown(int key)
Method used for knowing if a key is pressed.

Parameters:
key - The key code presents in 'Keyboard.' or in 'KeyEvent.'
Returns:
boolean - True when it's pressed, otherwise false.
See Also:
KeyEvent, Keyboard

addKey

public void addKey(int key)
Overloading the method void addKey(int key, int behavior), the behavior will be DETECT_INITAL_PRESS_ONLY.

Parameters:
key - The key code. The key code can be found in 'KeyEvent.'
See Also:
KeyEvent

addKey

public void addKey(int key,
                   int behavior)
Method used for adding a key to an instance of the keyboard and its behavior.

Parameters:
key - The key code. The key code can be found in 'KeyEvent.'.
behavior - The behavior of the key can be found in 'Keboard.' or in 'InputBase.'.
See Also:
KeyEvent, InputBase

removeKey

public void removeKey(int key)
Remove a key of the instance of the keyboard. If the key not exist in the instance of the keyboard don't generate any error.

See Also:
KeyEvent, Keyboard

setBehavior

public void setBehavior(int key,
                        int behavior)
Set a new behavior for a key. If the key not exist in the instance of the Keyboard it's not generate any error.

Parameters:
key - The key code. It can be found in 'KeyEvent.' or in 'Keyboard.'
See Also:
KeyEvent, Keyboard

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Specified by:
keyTyped in interface java.awt.event.KeyListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Specified by:
keyReleased in interface java.awt.event.KeyListener