I am to design a game where the end-user tries to guess a randomly generated number. I have set it up using Swing + jFrame on netbeans, but when I test it out and insert a digit and then click 'go', nothing will show up in my jLabel as expected.
Image of jFrame not working here - below the 'Go' button, there should be a message, weather that tells the user their guess was too high/low etc...
public class RandomNumberEYabrov extends javax.swing.JFrame {
//creates a random number stored globally
int RandNum = (int)Math.ceil(Math.random()*100);
//set variables
int intGuess;
boolean userGuess;
//convert users guess from string to integer
intGuess = Integer.parseInt(this.txtGuess.getText());
userGuess = false;
//while statement
while(!userGuess){
if(intGuess > RandNum){
this.lblOutput.setText("Too high! Try again!");
} else if(intGuess < RandNum){
this.lblOutput.setText("Too low! Try again!");
} else if (intGuess == RandNum){
this.lblOutput.setText("You got it!");
userGuess = true;
}
}
}
Aucun commentaire:
Enregistrer un commentaire