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

// This appears in Core Web Programming from
// Prentice Hall Publishers, and may be freely used
// or adapted. 1997 Marty Hall, hall@apl.jhu.edu.

/** Whenever an item is selected, it is displayed
 *  in the textfield that was supplied to the
 *  SelectionReporter constructor
 */

public class SelectionReporter implements ItemListener {
  private TextField selectionField;

  public SelectionReporter(TextField selectionField) {
    this.selectionField = selectionField;
  }

  public void itemStateChanged(ItemEvent event) {
    if (event.getStateChange() == event.SELECTED) {
      List source = (List)event.getSource();
      selectionField.setText(source.getSelectedItem());
    } else
      selectionField.setText("");
  }
}

