import java.awt.*;
import java.awt.event.*;  

public class NestedPanels3
    extends NestedPanels {
  public NestedPanels3() {
    super(); 
    ChoiceEventHandler chandler = new ChoiceEventHandler();     
    choice.addItemListener(chandler); 
    ButtonEventHandler bhandler = new ButtonEventHandler(); 
    bhandler.beActionListener(this); 
     
  }
  
  class ChoiceEventHandler implements ItemListener {
    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()); 
    }
  }
  class ButtonEventHandler implements ActionListener {
    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));        
        }        
      }
    }    
  }
  
}