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

/** A simple Dialog to ask a Question and to get one of the answers "yes", "no", or "cancel".
*/
public class QuestionDialog extends Dialog 
{

    /** The Buttons */
    protected Button yesButton, noButton, cancelButton;
    
    /** The state */
    protected int button;
    public final static int UNKNOWN = 0;
    public final static int YES = 1;
    public final static int NO = 2;
    public final static int CANCEL = 3;

    public QuestionDialog(Frame parent, String question) {
	super(parent, "Question", true);
	
	setBounds(50,50,250,100);
	setLocation(parent.getWidth()/2-125, parent.getHeight()/2-50);

	setLayout(new BorderLayout());
	
	yesButton = new Button("yes");
	yesButton.addActionListener( new ActionListener(){
		public void actionPerformed(ActionEvent e) {
		    buttonPressed(YES);
		}
	    });
	noButton  = new Button("no");
	noButton.addActionListener( new ActionListener(){
		public void actionPerformed(ActionEvent e) {
		    buttonPressed(NO);
		}
	    });
	cancelButton = new Button("cancel");
	cancelButton.addActionListener( new ActionListener(){
		public void actionPerformed(ActionEvent e) {
		    buttonPressed(CANCEL);
		}
	    });

	Label questionLabel = new Label(question);

	add(questionLabel, BorderLayout.CENTER);
	Panel buttons = new Panel(new FlowLayout(FlowLayout.CENTER));
	add(buttons, BorderLayout.SOUTH);
	
	buttons.add(yesButton);
	buttons.add(noButton);
	buttons.add(cancelButton);

    }

    /** Action: Button is pressed! */
    private void buttonPressed(int button) {
	this.button = button;
	setVisible(false);
    }

    /** Which button is selected? */
    public int getSelection() {
	return button;
    }
}

