Basic Events

------------------------------------------------
Sometimes it's easiest way to enable events is to just have a class implement a Listener interface or extend an Adapter class. The key restriction to keep in mind here is that a class can only extend one class, but classes may implement any number of interfaces.

------------------------------------------------
Implementing An Interface:


There are two items you should pay special attention to in this little applet:

1. When you add a key listener you write "addKeyListener(this);" The "this" refers to the class you are in which in this case implements KeyListener. So, the class serves as its own key listener. You can see that it provides method definitions for keyTyped(), keyPressed(), and keyReleased().
2. Also take notice of the "requestFocus();" line. This simply lets the applet know that it is the focus of keyboard events. Without this line it doesn't realize that it needs to pay attention to keyboard stuff.
------------------------------------------------
Another Example:



------------------------------------------------
Assignment: You will create an applet which listens for key strokes and responds by changing the background color when certain keys are entered. For instance, the background color should change to blue when the "b" key is pressed. Here are the color to letter mappings you should implement:
         Key     |    Color
       -----------------------
         y       |    yellow
         b       |    blue
         g       |    green
         r       |    red
         p       |    purple
         m       |    magenta
         o       |    orange
         x       |    black
         w       |    white
         c       |    cyan
To create a couple of these colors you will need to use the Color constructor which takes three int arguments corresponding to red, green, and blue color values. See the above code sample to see how it is used.