javalib.funworld
Class MyKeyAdapter

java.lang.Object
  extended by java.awt.event.KeyAdapter
      extended by javalib.funworld.MyKeyAdapter
All Implemented Interfaces:
KeyListener, EventListener

 class MyKeyAdapter
extends KeyAdapter

The implementation of callbacks for the key events.

Report all regular key presses, the four arrow keys, and some other special keys (backspace, delete, escape, page up, page down, home, end, tab, fkeys)

Ignore other key pressed events, key released events, etc.

Since:
August 2, 2007
Version:
March 5, 2013
Author:
Viera K. Proulx and Stephen Bloch

Field Summary
protected  World currentWorld
          the current World that handles the key events
 
Constructor Summary
protected MyKeyAdapter(World currentWorld)
          the KeyAdapter that handles the key events
 
Method Summary
protected  void displayInfo(KeyEvent e, String s)
          The key event major processor.
protected  void keyEventCallback(String keyString)
          The callback for the key events
 void keyPressed(KeyEvent e)
          Handle the key pressed event from the canvas.
 void keyTyped(KeyEvent e)
          Handle the key typed event from the canvas.
 
Methods inherited from class java.awt.event.KeyAdapter
keyReleased
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentWorld

protected World currentWorld
the current World that handles the key events

Constructor Detail

MyKeyAdapter

protected MyKeyAdapter(World currentWorld)
the KeyAdapter that handles the key events

Method Detail

displayInfo

protected void displayInfo(KeyEvent e,
                           String s)

The key event major processor. The code is adopted from the code provided by the Java documentation for key event processing.

We have to jump through some hoops to avoid trying to print non-printing characters such as Shift. (Not only do they not print, but if you put them in a String, the characters afterward won't show up in the text area.)


keyEventCallback

protected void keyEventCallback(String keyString)
The callback for the key events


keyPressed

public void keyPressed(KeyEvent e)

Handle the key pressed event from the canvas.

This is where we get the arrow keys.

Specified by:
keyPressed in interface KeyListener
Overrides:
keyPressed in class KeyAdapter
Parameters:
e - the KeyEvent that caused the callback

keyTyped

public void keyTyped(KeyEvent e)

Handle the key typed event from the canvas.

This is where we get the letter keys.

Specified by:
keyTyped in interface KeyListener
Overrides:
keyTyped in class KeyAdapter
Parameters:
e - the KeyEvent that caused the callback