C:\upload\java\Life\source\java\UI.java
/* ******************************************************************
    This prints out an initial messages and in-between game
    questions to the user.
********************************************************************* */
 
import java.awt.*;
import java.awt.event.*;

final class UI implements Constants, Strings, WindowListener  
{
    // Globals follow:
    private HowGameIsPlayedScreen askGameQuestionsScreen;
    private ScreenLocations screenLocations;
    private Frame parentFrame;
    private Objects objects;
    private Vars vars;

    private PopupWindow error;  /* For program exceptions -- shouldn't 
                                   happen.
                                */
    private boolean quit;               // If the user simply gets out.
    boolean userWantsToSeeInstructions; // See instructions? Parameter < quit > must
                                        // be false.
/* ******************************************************************
    Constuctor follows:
********************************************************************* */
       
    UI(Objects objects)  // Constructor.
    {
        this.objects = objects;
        this.vars = null;
        this.parentFrame = objects.GetParentFrame();
        this.screenLocations = objects.GetScreenLocations();
        askGameQuestionsScreen = null;
        quit = false; // Assume user wishes to see play.
        userWantsToSeeInstructions = true; 
        
        if (parentFrame == null)
        {
            System.out.println("Parent frame null in UI?!?!");
  //          System.exit(0);
        }

        /* We always instantiate an error class, just in case an
           error happens. This is global to everyone.
        */
        error = new PopupWindow(parentFrame, objects.GetScreenLocations(), ERROR_WINDOW_NAME);

    }       // End constuctor.

// Overidden methods from WindowListener interface:
// Only < windowClosing > matters:  user hit the "x" "close me" icon. We kill
// entire application; this is improper input.
public void windowClosing(WindowEvent e)
{
    quit = true;    // User pressed the "x" "close me" button. Get out.
    System.exit(0); // Kill everything.
}
public void windowActivated(WindowEvent e)  {}
public void windowDeactivated(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowIconified(WindowEvent e)  {}
public void windowOpened(WindowEvent e)     {}
public void windowClosed(WindowEvent e)     {}


    /* ******************************************************************
       Next displays "question" screens to user -- "Do you wish to see
       the instructions?" Note the returned boolean.
    ****************************************************************** */

    protected final void AskIfUserWantsToSeeInstructionsOrQuit(Vars vars)
    {
        String errorString = ((parentFrame != null) && (vars != null)) ? 
                             NULL_STRING : "parentFrame = " + parentFrame +
                             " vars = " + vars;
        if (!errorString.equals(NULL_STRING))
        {
            System.out.println("UI : AskIfUserWantsToSeeInstructions " + 
                                errorString);
            quit = true;
            return;
        }
        PopupWindow seeInstructions;  // This will be our display window.
        
    /* The first question is, "Do you wish to see the instructions? 
       (Yes) (No)." See class < PopupWindow > (separate file) for 
       implementation.
    */
       seeInstructions =  new PopupWindow(parentFrame, screenLocations,
                                          QUESTION); // Window name
                                         
        // Display the question:
        String [] strArr = {YES, NO, QUIT};   // Used in next:

        seeInstructions.ShowMessage(SEE_INSTRUCTIONS_STRING,
                                    strArr);      // Buttons

        /* The second thing seen is the rules of the game of Life. This 
           may or may not be displayed, depending upon the users 
           response to the dialog < seeInstructions >, of class 
           < PopupWindow >. (which see).
           
           Also note: if the user wishes to see the instructions, the
           caller (main Life program) needs to know so as to print out
           a few sample boards. Thus we communicate this to the calling
           program, as only it can make < repaint() > calls.
        */
        if ((seeInstructions.WhichButtonWasPressed()).equals(YES))
        {
            userWantsToSeeInstructions = true;
            
            PopupWindow displayInformationScreen = new PopupWindow(parentFrame, 
                                                       screenLocations,
                                                       INSTRUCTIONS);   // Window name.
            String [] stringArr = {OK, START_PLAYING, QUIT}; 

        // Show the user the first set of information:

            displayInformationScreen.ShowMessage(INSTRUCTIONS_STRINGS,
                                                 stringArr);           // Button.
            if ((displayInformationScreen.WhichButtonWasPressed()).equals(QUIT))
            {
                quit = true;
            }
            else if ((displayInformationScreen.WhichButtonWasPressed()).equals(START_PLAYING))
            {
                userWantsToSeeInstructions = false;
            }
        }
        else if ((seeInstructions.WhichButtonWasPressed()).equals(NO))    // Hit the "No" button.
        {
            userWantsToSeeInstructions = false;
        }
        else if ((seeInstructions.WhichButtonWasPressed()).equals(QUIT))
        {
            quit = true;
        }    
    }
    public boolean Quit() // Do we simply get out?
    {
        return quit;
    }
    public boolean UserWantsToSeeInstructions()
    {
        return userWantsToSeeInstructions;// Tell the patron if the
    }                                     // user requested instructions.
    

/* ******************************************************************
    Routine < ShowUserInterfaceInstructions() > follows. This shows the user the
    rest of the instructions, having seen the initial, "Do you wish
    for the instructions?" question, and if the answer was "Yes."
********************************************************************* */

    protected final void ShowUserInterfaceInstructions(Vars vars)
    {
        PopupWindow displayInformationScreen = new PopupWindow(parentFrame, 
                                                               screenLocations,
                                                               INSTRUCTIONS);
        String [] strArr = {OK, QUIT};   // Used in next:

        // Show the user the second set of information:

        displayInformationScreen.ShowMessage(BEFORE_GAME_STARTS_INSTRUCTIONS, // Info
                                             strArr);                       // Button.
        if ((displayInformationScreen.WhichButtonWasPressed()).equals(QUIT))
        {
            quit = true;
        }
    }

/* ******************************************************************
    Routine < GetGameParametersScreen() > follows. This fires up the big UI 
    that finds out how the user wishes to play the game.
********************************************************************* */

    protected final boolean GetGameParametersScreen(Vars vars)
    {
    /* We always ask the user basic questions: how many rows, columns, 
       play by mouse click or time delay ...

       Notable the < howGameIsPlayedScreen > class (which see, below) 
       is a sizable part of this file. It sets up a UI.
    
       Note: No-one uses the next class except us, and we instantiate it. It
       needs a pointer to < vars >, which we immediately feed it.
     */ 
        if (askGameQuestionsScreen == null)
        {
            askGameQuestionsScreen = new HowGameIsPlayedScreen(HOW_GAME_IS_PLAYED,
                                                               true,  // Modal.
                                                               parentFrame,
                                                               objects,
                                                               vars);
        }
        else
        {
            askGameQuestionsScreen.setBoardParameters();
        }
        askGameQuestionsScreen.addWindowListener(this);
        askGameQuestionsScreen.pack();
        askGameQuestionsScreen.setLocation(
                                 screenLocations.GetLocationOnScreen(askGameQuestionsScreen));
    //    do
        {
            askGameQuestionsScreen.setVisible(true);
        }//while (!askGameQuestionsScreen.Done());
        return askGameQuestionsScreen.playGame(); // False only if the user chose to get out.
    }
    
public String toString()
{
    return "class UI";
}

}  // End class < UI.java >.