Guessing Game

Here are some instructions on how to create the guessing game we coded in grade 10 in the NetBeans program.

1. Make a new project. All programs must go inside projects.

2. This will appear on the left hand side. The little java cup is the Project you made. It automatically creates a little box (package) that is called guessing for you.

3. Next, you are going to drag and drop together this interface.

4. To add the picture:

5. Right click on the button. Choose Event -> Action -> actionPerformed.

6. Switch to the "Source" tab (if the porgram hasn't done it automatically).

7. You need to add the code to the button's actionPerformed method.

private void jButton1ActionPerformed(java.awt.event.ActionEvent    evt) {//GEN-FIRST:event_jButton1ActionPerformed
   int guess = Integer.parseInt(jTextField1.getText());
   jTextField1.setText("");
   if (num==guess)
   {jLabel3.setText("You win! You guessed "+num+" in "+tries+"    guesses.");
   jLabel5.setText("The number has selected a new number to play again.");
   num = (int)(Math.round(Math.random()*100)+1);
   tries=0;
   }
   else if(guess>num)
   {tries++;
   jLabel3.setText(guess+ " is too high. Guess again.");
   jLabel5.setText("You have taken "+tries+" guesses.");
   }
   else
   {tries++;
   jLabel3.setText(guess+ " is too low. Guess again.");
   jLabel5.setText("You have taken "+tries+" guesses.");
   }
   }

8. Right click on the JFrame inside the package (mine is called GuessingGame.java).

9. Test your game and make necessary changes.

10. Extra files that are created (Look in the folder you told NetBeans to save the files to):

11. Create the Magic 8 Ball game we created in grade 10 by modelling these instructions. Here is the GUI.