import java.awt.*;

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

/** A Popup that takes an array of colornames and
 *  an array of colors, setting a specified
 *  component to the corresponding color when
 *  a colorname is chosen.
 */

public class ColorPopup extends Popup {
  private Component target;
  private String[] colorNames;
  private Color[] colors;

  public ColorPopup(Frame source) {
    super(source);
  }
  
  public void display(Component target,
                      String[] colorNames,
                      Color[] colors,
                      int x, int y) {
    this.target = target;
    this.colorNames = colorNames;
    this.colors = colors;
    display(colorNames, x, y);
  }

  public void doAction() {
    int colorIndex = getList().getSelectedIndex();
    if (colorIndex >= 0)
      target.setBackground(colors[colorIndex]);
    target.repaint();
  }
}
    
