Sometimes, a better encapsulation results from combining inheritance
from the component class with implementation of the listener.
The component then becomes its own listener.
class ColorButton extends Button implements ActionListener {
private Color ourColor;
public ColorButton (Color c, String name) {
super (name); // create the button
ourColor = c; // save the color value
addActionListener (this); // add ourselves as listener
}
public void actionPerformed (ActionEvent e) {
// set color for middle panel
setFromColor (ourColor);
}
}