| Simple Delegation program (3) | |
/**
* A listener object that is invoked when a Button is activated
* It finds the Button's label and sets it in a Label
*/
class SimpleListener implements ActionListener {
private Label label;
public SimpleListener(Label l) {
// the listener needs to know the Label it will act on
label = l;
}
public void actionPerformed(java.awt.event.ActionEvent e) {
// get the label showing in whichever Button was pressed
String name = e.getActionCommand();
// set this in the Label object
label.setText(name);
}
}
| Slide 41 | ©Copyright 1997 | Jan Newmarch |