higher Or Lower
setup Form
import Package
- put the following import at the very top (i.e. on the first line, so that everything else is moved down) of your Source code:
import java.util.Random;
public Variable And Constructor
- put the following public variable declaration between the jFrame Class Declaration and jFrame Constructor as shown:
public int computer_guess;
the Constructor executes code when the form initializes. Add the following code as shown in the previous image (the initComponents() will already be there just leave it there)
Random seed = new Random();
computer_guess = seed.nextInt(10) + 1;
btnGuess
int human_guess;
human_guess = Integer.valueOf(txtGuess.getText());
if(human_guess == computer_guess){
lblFeedback.setText("correct");
}
if(human_guess > computer_guess){
lblFeedback.setText("lower");
}
if(human_guess < computer_guess){
lblFeedback.setText("higher");
}