CSE115
Class KeyInteractor

java.lang.Object
  |
  +--CSE115.KeyInteractor
All Implemented Interfaces:
ActionListener, EventListener

public abstract class KeyInteractor
extends Object
implements ActionListener

A class for listening to any type of key press. Based on KeyInteractor by Matt Chotin.

Author:
Phil Ventura
See Also:
Created: Fri Nov 23 16:08:31 2001

Field Summary
static int DOWN_ARROW
          The code for the down arrow key.
static int LEFT_ARROW
          The code for the left arrow key.
static int RIGHT_ARROW
          The code for the right arrow key.
static int UP_ARROW
          The code for the up arrow key.
 
Constructor Summary
KeyInteractor(Panel panel, char keyChar)
          Create a KeyInteractor that will respond whenever the key with the passed in character is pressed.
KeyInteractor(Panel panel, int keyCode)
          Create a KeyInteractor that will respond whenever the key is pressed.
 
Method Summary
 void actionPerformed(ActionEvent e)
          Normal users need not deal with this method!
 void disable()
          Turn the KeyInteractor off so that it will not call keyPressed.
 void enable()
          Turn the KeyInteractor on so that it will call keyPressed.
 boolean getEnabled()
          Is this KeyInteractor enabled or disabled?
abstract  void keyPressed()
          Subclasses should override to do something useful.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UP_ARROW

public static final int UP_ARROW
The code for the up arrow key.

See Also:
Constant Field Values

DOWN_ARROW

public static final int DOWN_ARROW
The code for the down arrow key.

See Also:
Constant Field Values

LEFT_ARROW

public static final int LEFT_ARROW
The code for the left arrow key.

See Also:
Constant Field Values

RIGHT_ARROW

public static final int RIGHT_ARROW
The code for the right arrow key.

See Also:
Constant Field Values
Constructor Detail

KeyInteractor

public KeyInteractor(Panel panel,
                     char keyChar)
Create a KeyInteractor that will respond whenever the key with the passed in character is pressed.

Parameters:
panel - the Panel that will "hear" the keypresses, a good choice is the highest level panel
keyChar - the character on top of the key, pass ' ' for space, 'a' for A without the Shift key and 'A' for A with the Shift key

KeyInteractor

public KeyInteractor(Panel panel,
                     int keyCode)
Create a KeyInteractor that will respond whenever the key is pressed.

Parameters:
panel - the Panel that will "hear" the keypresses, a good choice is the highest level panel
keyCode - the code for the key being pressed.
Method Detail

enable

public void enable()
Turn the KeyInteractor on so that it will call keyPressed.

See Also:
disable, getEnabled

disable

public void disable()
Turn the KeyInteractor off so that it will not call keyPressed.

See Also:
enable, getEnabled

getEnabled

public boolean getEnabled()
Is this KeyInteractor enabled or disabled?

Returns:
true for enabled and false for disabled
See Also:
enable, disable

keyPressed

public abstract void keyPressed()
Subclasses should override to do something useful. This will get called occasionally as long as the key is pressed.


actionPerformed

public void actionPerformed(ActionEvent e)
Normal users need not deal with this method!

Called by the KeyStroke to indicate that it was pressed. Calls our keyPressed method.

Specified by:
actionPerformed in interface ActionListener
Parameters:
e - we do nothing with this parameter