import java.awt.*;
import java.awt.event.*;
public class NestedPanels2 extends NestedPanels
implements ActionListener, ItemListener {
public NestedPanels2() {
super();
choice.addItemListener(this);
beActionListener(this);
}
public void itemStateChanged(ItemEvent event) {
if (event!=null)
System.out.println("ItemStateChanged: " + event);
Choice choice = (Choice) event.getSource();
if (choice != null)
messageBar.setText("Choice selected: " + event.getItem());
}
public void actionPerformed(ActionEvent event) {
if (event!=null)
System.out.println("ActionPerformed: " + event);
Button source = (Button) event.getSource();
if (source != null)
messageBar.setText("Button pushed: " + source.getLabel());
}
protected void beActionListener(Component comp) {
if (comp != null) {
if (comp instanceof Button) {
Button button = (Button) comp;
button.addActionListener(this);
} else if (comp instanceof Container) {
Container container = (Container) comp;
int n = container.getComponentCount();
for (int i = 0; i < n; i++)
beActionListener(container.getComponent(i));
}
}
}
}