------------------------------------------
As you saw in the last lesson you can handle events in a variety of ways.
In fact we could make a four by two matrix representing our options:
| Adapter Classes | Listener Interfaces |
Outer Classes | this lesson | this lesson |
Classes | next lesson | next lesson |
Inner Classes | two lessons from now | two lessons from now |
Low-Level | three lessons from now | three lessons from now |
For further information study these pages:
Java Event Model
Examples of six different approaches (EXCELLENT
EXAMPLES!)
Examples Using Inner Classes
Example Using Low Level Event Handling
------------------------------------------
Java 1.1 Event Types, Listeners, and Listener Methods:
Event Class | Listener Interface | Listener Methods |
ActionEvent | ActionListener | actionPerformed() |
AdjustmentEvent | AdjustmentListener | adjustmentValueChanged() |
ComponentEvent | ComponentListener |
componentHidden() componentMoved() componentResized()
componentShown() |
ContainerEvent | ContainerListener |
componentAdded() componentRemoved()
|
FocusEvent | FocusListener |
focusGained() focusLost() |
ItemEvent | ItemListener | itemStateChanged() |
KeyEvent | KeyListener | keyPressed() keyReleased()
keyTyped() |
MouseEvent | MouseListener |
mouseClicked() mouseEntered() mouseExited()
mousePressed() mouseReleased() |
MouseMotionListener |
mouseDragged() mouseMoved() |
TextEvent | TextListener | textValueChanged() |
WindowEvent | WindowListener |
windowActivated() windowClosed() windowClosing()
windowDeactivated() windowDeiconified()
windowIconified() windowOpened() |
Any Listener interface which provides more than one method has a corresponding
Adapter class. When you implement an interface you must provide definitions
for all of its methods. When you extend a class you only provide definitions
for the methods you wish to override. This is the advantage of using Adapter
classes: You only have to provide definitions for the methods you wish to
use.
------------------------------------------
Example One: External Class, Listener Interface, List Component:
Notice the constructor for the IL class. It takes an instance of the list
class as an argument. This is so items from the list class can be accessed
within the IL class. This would not be necessary if we had used inner classes.
------------------------------------------
Example Two: External Class, Adapter Class, Scrollbar Component:
------------------------------------------
Thinking In Java:
Read the following sections from chapter thirteen: "Check Boxes and Radio
Buttons," "Drop-down Lists," "Lists," and "Menus."
|
------------------------------------------
Assignment: Recreate the following applet:
You will need to use panels to recreate the exact layout... but you don't
have to be perfect, but it will still have to be pretty darn good.