Java Guessing Game with GUI

Here are the java files printed to PDF:

Important things to note:

  • contains a chunk of Netbeans-generated code in the middle in a method called initComponents(). Ignore it.
  • Notice that the logic of the game itself,, knows nothing about the UI. All it can do is respond to requests to:
    • start the game
    • receive and process a guess
    • return the current status message
    • say whether or not the game is over
  • imports java.util.HashSet and java.util.Set. This is a mistake. They are unused. So you can ignore them.
  • Notice that I have edited to the GuessingGameUI constructor to accept a handle to the GuessingGame object itself. This is so that the GuessingGameUI can send and receive messages from the GuessingGame. I have to keep a hold of this handle for the duration of the program, so I assign it to a global variable called theGame. That way, the UI can always contact theGame when it needs to (see the button code, for instance).
  • In the GuessingGameUI, notice that there are only two methods apart from the constructor. They are what to do when the New Game button is pressed, and what to do when the Guess button is pressed.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s