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

/**
 *  MyFirstDialog class
 *
 * A sample Dialog to illustrate the placing of GUI objects and event handling
 */

class MyFirstDialog extends Dialog implements ActionListener
{

//----------------------------------
//    Data Members
//----------------------------------
    
    /**
     * Default frame width
     */
    private static final int FRAME_WIDTH    = 300;
    
    /**
     * Default frame height
     */
    private static final int FRAME_HEIGHT   = 200;
    
    /**
     * X coordinate of the frame default origin point
     */
    private static final int FRAME_X_ORIGIN = 150;
    
    /**
     * Y coordinate of the frame default origin point
     */
    private static final int FRAME_Y_ORIGIN = 250;

    /**
     * Default width for buttons
     */
    private static final int BUTTON_WIDTH  = 60;
     
    /**
     * Default height for buttons
     */
    private static final int BUTTON_HEIGHT = 30;

    /**
     * The GUI button for Cancel
     */
    private Button cancelButton;
    
    
    /**
     * The GUI button for OK
     */
    private Button okButton;
    
   

//----------------------------------
//    Constructors
//----------------------------------
                                
    /**
     * Default constructor
     */
    public MyFirstDialog(Frame owner)
    {
        this(owner, true);
    }
   
   
    /**
     * Constructs this object with the specified owner and 
     * modality
     */
    public MyFirstDialog(Frame owner, boolean modal)
    {
        super(owner, modal);
        //set the frame properties
        setSize      (FRAME_WIDTH, FRAME_HEIGHT);
        setResizable (false);
        setTitle     ("Program MyFirstDialog");
        setLocation  (FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
        setLayout    (null);
        
        //create and place two buttons on the frame
        okButton = new Button("OK");
        okButton.setBounds(100, 150, BUTTON_WIDTH, BUTTON_HEIGHT);
        add(okButton);
        
        cancelButton = new Button("CANCEL");
        cancelButton.setBounds(170, 150, BUTTON_WIDTH, BUTTON_HEIGHT);
        add(cancelButton);
  
        //register this frame as an action listener of the two buttons
        cancelButton.addActionListener(this);
        okButton.addActionListener(this);
        
        //register a ProgramTerminator object as the window listener of this frame
        addWindowListener(new ProgramTerminator());
    }

//-------------------------------------------------
//      Public Methods:
// 
//          void    actionPerformed   (   ActionEvent        )
//
//------------------------------------------------
                                
    /**
     * Standard method to respond the action event.
     * 
     * @param event the ActionEvent object
     *
     */   
    public void actionPerformed(ActionEvent event) 
    {
        Button clickedButton = (Button) event.getSource();
        
        if (clickedButton == cancelButton) {
           setTitle("You clicked CANCEL");
        }
        else { //the event source must be okButton
           setTitle("You clicked OK");
        }
    }
   
}