Home > Computer Programming > Java Guessing Game with GUI

Java Guessing Game with GUI

January 15, 2014 Leave a comment Go to comments

Here are the java files printed to PDF:

Important things to note:

  • GuessingGameUI.java 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, GuessingGame.java, 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
  • GuessingGame.java 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.
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s