// Add JButton and JList components to the panel.
// Implicit super() call here invokes the superclass constructor
// Add a "Clear" button to the panel.
// Handle button events with an action listener
JButton clear = new JButton("Clear");
clear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { clear(); }
});
this.add(clear);
// Add a JList to allow color choices.
// Handle list selection events with a ListSelectionListener.
final JList colorList = new JList(colorNames);
colorList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
setColor(colors[colorList.getSelectedIndex()]);
}
});
this.add(colorList);