public class NestedPanels2 extends NestedPanels
1: import java.awt.*;
2: import java.awt.event.*;
3:
4: public class NestedPanels2 extends NestedPanels
5: implements ActionListener, ItemListener {
6: public NestedPanels2() {
7: super();
8: choice.addItemListener(this);
9: beActionListener(this);
10:
11: }
12:
13: public void itemStateChanged(ItemEvent event) {
14: if (event!=null)
15: System.out.println("ItemStateChanged: " + event);
16: Choice choice = (Choice) event.getSource();
17: if (choice != null)
18: messageBar.setText("Choice selected: " + event.getItem());
19: }
20: public void actionPerformed(ActionEvent event) {
21: if (event!=null)
22: System.out.println("ActionPerformed: " + event);
23: Button source = (Button) event.getSource();
24: if (source != null)
25: messageBar.setText("Button pushed: " + source.getLabel());
26: }
27: protected void beActionListener(Component comp) {
28: if (comp != null) {
29: if (comp instanceof Button) {
30: Button button = (Button) comp;
31: button.addActionListener(this);
32: } else if (comp instanceof Container) {
33: Container container = (Container) comp;
34: int n = container.getComponentCount();
35: for (int i = 0; i < n; i++)
36: beActionListener(container.getComponent(i));
37: }
38: }
39: }
40:
41: }