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

// A variation of a class that appears in Core Web
// Programming from Prentice Hall. May be freely used
// or adapted.
// 1998 Marty Hall, http://www.apl.jhu.edu/~hall/java/

/** A modal dialog box with two buttons: Yes and No.
 *  Clicking Yes exits Java. Clicking No exits the
 *  dialog. Used for confirmed quits from frames.
 */

class Confirm extends Dialog implements ActionListener {
  private Button yes, no;

  public Confirm(Frame parent) {
    super(parent, "Confirmation", true);
    setLayout(new FlowLayout());
    add(new Label("Really quit?"));
    yes = new Button("Yes");
    yes.addActionListener(this);
    no  = new Button("No");
    no.addActionListener(this);
    add(yes);
    add(no);
    pack();
    setVisible(true);
  }

  public void actionPerformed(ActionEvent event) {
    if (event.getSource() == yes)
      System.exit(0);
    else
      dispose();
  }
}
