| Introduction to OOP | Chapter 22: The AWT and Swing : | next | previous | audio | real | text |
The user places an instance of a class into the window. Most use the listener event model to notify when they are changed.
Button butn = new Button ("do it!");
add("North", butn); // place at top of screen
butn.addActionListener (new doIt()); // add listener
..
private class doIt implements ActionListener {
public void actionPerformed (ActionEvent e) {
// what ever do it does
...
}
}
The listener model avoids the need for inheritance from the component class.