Question: (for java) Create a GUI application that plays a simple guessing game. Give it two buttons labeled Odd and Even. The user must guess whether
(for java) Create a GUI application that plays a simple guessing game. Give it two buttons labeled Odd and Even. The user must guess whether a secret number is odd or even by clicking one of these buttons. After a guess is made, the application should display either Congratulations, you are correct! or Sorry, your are wrong. In either case, also display The secret number was: followed by the secret number. Use lables for these three messages.
The program will have a private instance variable secretNumber of type long that holds the secret number. You will need to set it in the init() method using the following line of code:
secretNumber = java.util.Calendar.getInstance().getTimeInMillis() % 100;
In the actionPerformed() method, check which button was pressed and make the appropriate response label visible. After that, make the two buttons invisible (only one guess is allowed) and the label containing the secret number visible.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
