C:\upload\java\Life\source\java\Objects.java
/*******************************************************************
    Next instantiates all objects (except arrays) that the progam 
    needs.

    Note: order of instantiation is very important, as the constructors
    of some objects set up pointers to other objects. See the 
    documentation. 
******************************************************************** */  
import java.awt.*;

final class Objects implements Strings
{
    private Frame parentFrame;
    private boolean instantiationsSucceeded;
    
    private static ScreenLocations screenLocations;    /* Where is a window to be located
                                                          on the screen?
                                                       */
    private static HandleButtons buttons;  // Handles visibility & cursors of buttons.
    private static Initializations initializations;    // Handles initialization of variables.

        /* See next class. Via it the board is painted. A canvas.
        */
    private static PaintBoardAndComputeNextGeneration paintBoardAndComputeNextGeneration;
    private static GenerationNumberCanvas genNum;  /* Holds what generation we 
                                               are on. A canvas.
                                            */
    private static BoardUtilities boardUtilities;          /* General board routines,
                                                       such as, "Is anyone alive?",
                                                       or, "Compute the next generation
                                                    */
    private static ManageBoardCoordinates boardCoordinates;/* Takes care of converting mouse
                                                       click pixel locations to cells,
                                                       and cells to pixel locations.
                                                    */
    private static UI ui;                  // Sets up UI for user
    private static RepeatPattern repeat;   // Are we in a repeating pattern?    
    
    // Constructor. Makes objects.

    Objects(Frame parentFrame, Graphics offScreenGraphics)
    {
        String errorString = ((parentFrame       != null) && 
                              (offScreenGraphics != null)) ? 
                               NULL_STRING : "parentFrame = " + parentFrame +
                             " offScreenGraphics = " + offScreenGraphics;
        if (!errorString.equals(NULL_STRING))
        {
            System.out.println("Error, null pointer, Objects " + errorString);
            return;
        }

        repeat                             = null;  // These
        boardUtilities                     = null;  // had
        paintBoardAndComputeNextGeneration = null;  // better
        genNum                             = null;  // not be
        ui                                 = null;  // null
        buttons                            = null;  // when
        initializations                    = null;  // we're
        boardCoordinates                   = null;  // done.

        instantiationsSucceeded = true;   // Assume good.
        
        this.parentFrame = parentFrame;

        try
        {
        /* Next handles buttons, setting their visibility and cursors.

            Maintenance Note: Order of instantiation is important:
            
                1) Class < Buttons > (null constructor)
                2) Class < ScreenLocations >(requires buttons, just instantiated before)
                3) Initializations (takes a < this > pointer as it needs
                   a < screenLocations > pointer, just instantiated before).

                After these three, it is not as important.
               
            It takes a < this > pointer to have access to the above-instantiated
            buttons, the cursors, and the booleans <  clickLiveCellsViaMouse > and
            < waitForTimeDelay >.
        */
        buttons = new HandleButtons();
        /* Now we instantiate classes this program uses. 

           We start with classes that don't need other classes, as
           some take < this > pointers to us, and may need classes
           already instantiated. These are last, to avoid null pointer
           problems.
        */

        /* Next sets screen locations of windows and buttons. It takes
           a  pointer to the buttons.
         */
           screenLocations = new ScreenLocations(buttons/*, parentFrame*/);

            /* Next takes a < this > pointer to have access to our variables.
            */
            initializations = new Initializations(this);

            /* Next takes care of board coordinates. We tell it how many rows 
               and columns the board has as well as pixels per cell as soon as 
               we know.

               It takes a < this > pointer to reference variables, specifically,
               rows, columns, and pixels per cell, and the parent frame.
            */
            
            boardCoordinates = new ManageBoardCoordinates(parentFrame, screenLocations);

            /* Class to tell us if we are in a repeating pattern. It takes
               a < this > pointer to have access to < oldBoards >, 
               < thisGeneration>, < rows >, < columns >, < generation > , 
               and the parent frame.
            */
            repeat = new RepeatPattern(parentFrame, this);

            /* The next holds various short routines that the code uses in 
               many places. These routines do things like computing the next 
               generation, determining if a anyone is still alive, and board 
               initialization. They generally loop through the boards.

               Note it only uses the < parentFrame > parameter.
            */
            boardUtilities = new BoardUtilities(parentFrame, screenLocations);

    /* Important maintenance note: Parameter < setUpPaintingOfBoard > takes
       pointers to parameters < paintBoard > and < genNum >,
       so MUST be instantiated after them.
    */
            /* The board lives on a canvas, set in 
               < class PaintBoardCanvas > (which see). 
            */
            paintBoardAndComputeNextGeneration = new PaintBoardAndComputeNextGeneration(
                                              parentFrame, this,
                                              screenLocations,
                                              0, 0); /* Set size to
                                                        "zero" for now  */

        /* Instantiate the canvas on which the generation number lives.
           This object takes a < this > pointer for two reasons -- access
           to current generation, and a frame for its error class.
        */
            genNum = new GenerationNumberCanvas(parentFrame, screenLocations,
                                                0, 0); /* Set size to 
                                                        "zero" for now    */

        /*  The next is a class where the dirty work of telling/asking 
            the user information is stashed -- the big UI. See it to 
            understand what it does and how. It takes a < this > pointer,
            but only uses variables, no objects.
        */
            ui = new UI(this);
        }
        catch(RuntimeException e)
        {
            instantiationsSucceeded = false;    // Instantiation failed ?!?!?!
        }
        // And, for good measure:
        
        instantiationsSucceeded &= ((repeat != null)                             &&
                                    (boardUtilities != null)                     &&
                                    (paintBoardAndComputeNextGeneration != null) &&
                                    (genNum != null)                             &&
                                    (ui != null)                                 && 
                                    (parentFrame != null)                        &&
                                    (offScreenGraphics != null)                  &&
                                    (buttons != null)                            &&
                                    (initializations != null)                    &&
                                    (boardCoordinates != null));

        errorString = (instantiationsSucceeded) ? 
                               NULL_STRING : "Null Pointer, < objects.java >.";
        if (!errorString.equals(NULL_STRING))
        {
            System.out.println("Error, null pointer, Objects " + errorString);
            return;
        }
    }

/*******************************************************************
    Any problems with instantiations? Next tells our patron.
******************************************************************** */  

    protected final boolean InstantiationsSucceeded()
    {
        return instantiationsSucceeded;
    }

    // Get the frame:

    protected final Frame GetParentFrame()
    {
        return parentFrame;
    }
    
    // Classes follow:

    // Screen locations:

    protected final void SetScreenLocations(ScreenLocations screenLocations)
    {
        this.screenLocations = screenLocations;
    }
    protected final ScreenLocations GetScreenLocations()
    {
        return screenLocations;
    }
    // Initializations:

    protected final void SetInitializations(Initializations initializations)
    {
        this.initializations = initializations;
    }
    protected final Initializations GetInitializations()
    {
        return initializations;
    }

    // Generation Number Canvas:

    protected final void SetGenNum(GenerationNumberCanvas genNum)
    {
        this.genNum = genNum;
    }
    protected final GenerationNumberCanvas GetGenNum()
    {
        return genNum;
    }

    // Paint Board Canvas:

    protected final void SetPaintBoardAndComputeNextGeneration(
                                PaintBoardAndComputeNextGeneration 
                                        paintBoardAndComputeNextGeneration)
    {
        this.paintBoardAndComputeNextGeneration = paintBoardAndComputeNextGeneration;
    }
    protected final PaintBoardAndComputeNextGeneration GetPaintBoardAndComputeNextGeneration()
    {
        return paintBoardAndComputeNextGeneration;
    }

    // The user interface:

    protected final void SetUi(UI ui)
    {
        this.ui = ui;
    }
    protected final UI GetUi()
    {
        return ui;
    }

    // Board utilities:

    protected final void SetBoardUtilities(BoardUtilities boardUtilities)
    {
        this.boardUtilities = boardUtilities;
    }
    protected final BoardUtilities GetBoardUtilities()
    {
        return boardUtilities;
    }

    // Are we in a repeating pattern?

    protected final void SetRepeatPattern (RepeatPattern repeat)
    {
        this.repeat = repeat;
    }
    protected final RepeatPattern GetRepeatPattern()
    {
        return repeat;
    }

    // Board coordinates:

    protected final void SetBoardCoordinates(ManageBoardCoordinates boardCoordinates)
    {
        this.boardCoordinates = boardCoordinates;
    }
    protected final ManageBoardCoordinates GetBoardCoordinates()
    {
        return boardCoordinates;
    }
    protected final HandleButtons GetButtons()
    {
        return buttons;
    }    
}