maths Blaster
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 Variables And Constructor
- put the following public variable declarations between the jFrame Class Declaration
mathsBlasterForm
(or whatever you called your jFrame) and the jFrame Constructor mathsBlasterForm()
(or whatever you called your jFrame) as shown:
public int sum_total;
public int num_right = 0;
public int num_wrong = 0;
btnNewSum
Random seed = new Random();
int num1 = seed.nextInt(10)+1;
int num2 = seed.nextInt(10)+1;
lblNum1.setText(String.valueOf(num1));
lblNum2.setText(String.valueOf(num2));
sum_total = num1 + num2;
btnCheck
int user_guess;
user_guess = Integer.valueOf(txtAnswer.getText());
if(user_guess == sum_total){
num_right++;
lblRight.setText(String.valueOf(num_right));
}
else
{
num_wrong++;
lblWrong.setText(String.valueOf(num_wrong));
}