Create an application that uses a card layout manager to enable two people to play a guessing game. The initial card will have two text fields in which the players will enter their names. The StartGame button will bring up a new card, the numberentry card, that has a text field in which a player can enter a secret integer value.

The PlayGame button will bring up a second card that has three buttons and
a text field. The player will enter a guess value in the text field and then press one of the three buttons. The greater button will display true or false depending on whether the player’s guess value is greater than the secret value. The less button will display true or false depending on whether the players guess value is less than the secret value. The equal button will display true or false depending on whether the players guess value is equal to the secret value. Once the player correctly guesses the integer value, the number of guesses made is added to that player’s total score and displayed in a text field. Pressing the NewNumber button will bring back the number-entry card. Players should alternate between picking the secret number and guessing the value of the secret number. You should have labels that will display each player’s current score.

This application demonstrates the use of a card layout. Note that in this game, lower scores are better. (This is why the score is shown as blots.) To simplify the actionPerformed method, we break each button’s action out into a method. The setup code is long, but uncomplicated.

When constructing this application, it would be a good idea to do it iteratively.
1) Get the card logic to work correctly first (switching between cards)
2) Complete the start card. (Name entry works)
3) Complete the secret number entry card. (A player can enter their secret number)
4) Do the guess card. (Add each button and make it work.)


See the code in in GuessingGame.java..

Computer Science & Information Technology

You might also like to view...

Which of the following statements best describes an IP address?

A. It is a unique identifier burned into the NIC when it is manufactured. B. It is a unique dotted decimal number assigned to every network node. C. It is a number shared by all computers on the same network. D. It is a number assigned only to routers, identifying their priority ratings.

Computer Science & Information Technology

Brightness of a picture refers to the light to dark ________ of the image

A) factor B) compression C) ratio D) contrast

Computer Science & Information Technology

Discuss the creation of custom slide layouts.

What will be an ideal response?

Computer Science & Information Technology

Colors that are descriptive of the flavors contained in a package can be copyright protected.

a. true b. false

Computer Science & Information Technology