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

/**
 * Class to display error messages in a dialog box w/ an Ok button
 *
 * @see java.awt.Dialog
 */

public class ErrorDialog extends Dialog implements ActionListener,
  WindowListener , KeyListener
{
  private Button okButton = new Button("Ok");

  /**
   * Constructor
   *
   * @param parent the frame which is our parent
   * @param body the text to display as an error
   */
  
  public ErrorDialog(Frame parent, String body)
  {
    super(parent,"Error",true);

    add("Center",new Label(body,Label.CENTER));
    add("South",okButton);
    okButton.addActionListener(this);
    addWindowListener(this);
    pack();
  }

  /**
   * Constructor
   *
   * @param parent the frame which is our parent
   * @param title the title for the Dialog box
   * @param body the text to display as an error
   */
  
  public ErrorDialog(Frame parent, String title, String body)
  {
    super(parent,title,true);

    add("Center",new Label(body,Label.CENTER));
    add("South",okButton);
    okButton.addActionListener(this);
    addWindowListener(this);
    pack();
  }

  //Below here is Action Handling stuff
  public void actionPerformed(ActionEvent event)
  {
    Object src = event.getSource();
        
    if (src.equals(okButton)) {
      dispose();
    }
  }

  public void keyTyped(KeyEvent e)
  {
    if (e.getKeyChar() == '\n') dispose();
  }

  public void keyPressed(KeyEvent e)
  {
  }

  public void keyReleased(KeyEvent e)
  {
  }

  public void windowClosed(WindowEvent event)
  {
  }

  public void windowDeiconified(WindowEvent event)
  {
  }

  public void windowIconified(WindowEvent event)
  {
  }

  public void windowActivated(WindowEvent event)
  {
  }

  public void windowDeactivated(WindowEvent event)
  {
  }

  public void windowOpened(WindowEvent event)
  {
  }

  public void windowClosing(WindowEvent event)
  {
    dispose();
  }
}

