| C:\upload\java\Life\source\java\UI.java |
import java.awt.*;
import java.awt.event.*;
final class UI implements Constants, Strings, WindowListener
{
private HowGameIsPlayedScreen askGameQuestionsScreen;
private ScreenLocations screenLocations;
private Frame parentFrame;
private Objects objects;
private Vars vars;
private PopupWindow error;
private boolean quit;
boolean userWantsToSeeInstructions;
UI(Objects objects)
{
this.objects = objects;
this.vars = null;
this.parentFrame = objects.GetParentFrame();
this.screenLocations = objects.GetScreenLocations();
askGameQuestionsScreen = null;
quit = false;
userWantsToSeeInstructions = true;
if (parentFrame == null)
{
System.out.println("Parent frame null in UI?!?!");
}
error = new PopupWindow(parentFrame, objects.GetScreenLocations(), ERROR_WINDOW_NAME);
}
public void windowClosing(WindowEvent e)
{
quit = true;
System.exit(0);
}
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) {}
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;
seeInstructions = new PopupWindow(parentFrame, screenLocations,
QUESTION);
String [] strArr = {YES, NO, QUIT};
seeInstructions.ShowMessage(SEE_INSTRUCTIONS_STRING,
strArr);
if ((seeInstructions.WhichButtonWasPressed()).equals(YES))
{
userWantsToSeeInstructions = true;
PopupWindow displayInformationScreen = new PopupWindow(parentFrame,
screenLocations,
INSTRUCTIONS);
String [] stringArr = {OK, START_PLAYING, QUIT};
displayInformationScreen.ShowMessage(INSTRUCTIONS_STRINGS,
stringArr);
if ((displayInformationScreen.WhichButtonWasPressed()).equals(QUIT))
{
quit = true;
}
else if ((displayInformationScreen.WhichButtonWasPressed()).equals(START_PLAYING))
{
userWantsToSeeInstructions = false;
}
}
else if ((seeInstructions.WhichButtonWasPressed()).equals(NO))
{
userWantsToSeeInstructions = false;
}
else if ((seeInstructions.WhichButtonWasPressed()).equals(QUIT))
{
quit = true;
}
}
public boolean Quit()
{
return quit;
}
public boolean UserWantsToSeeInstructions()
{
return userWantsToSeeInstructions;
}
protected final void ShowUserInterfaceInstructions(Vars vars)
{
PopupWindow displayInformationScreen = new PopupWindow(parentFrame,
screenLocations,
INSTRUCTIONS);
String [] strArr = {OK, QUIT};
displayInformationScreen.ShowMessage(BEFORE_GAME_STARTS_INSTRUCTIONS,
strArr);
if ((displayInformationScreen.WhichButtonWasPressed()).equals(QUIT))
{
quit = true;
}
}
protected final boolean GetGameParametersScreen(Vars vars)
{
if (askGameQuestionsScreen == null)
{
askGameQuestionsScreen = new HowGameIsPlayedScreen(HOW_GAME_IS_PLAYED,
true,
parentFrame,
objects,
vars);
}
else
{
askGameQuestionsScreen.setBoardParameters();
}
askGameQuestionsScreen.addWindowListener(this);
askGameQuestionsScreen.pack();
askGameQuestionsScreen.setLocation(
screenLocations.GetLocationOnScreen(askGameQuestionsScreen));
{
askGameQuestionsScreen.setVisible(true);
}
return askGameQuestionsScreen.playGame();
}
public String toString()
{
return "class UI";
}
}