import java.awt.*;
import java.awt.event.*;

/** Whenever an item is selected, it is displayed
 *  in the textfield that was supplied to the
 *  SelectionReporter constructor.
 *
 *  Taken from Core Web Programming from 
 *  Prentice Hall and Sun Microsystems Press,
 *  http://www.corewebprogramming.com/.
 *  &copy; 2001 Marty Hall and Larry Brown;
 *  may be freely used or adapted. 
 */

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("");
  }
}