Page 1 of 1

GUI game ... help

Posted: Fri Mar 21, 2003 12:05 pm
by Guest
I'm doing a gui number game where the user has to guess 3 random numbers, the result of each guess is outputted in 3 textfields

the random numbers are in an array as shown (In the actionPerformed method)

int i = 0, Count = 0;

RandomNumber = Math.round(Math.random() * 9);
RandomNumber[i + 1] = Math.round(Math.random() * 9);
RandomNumber[i + 2] = Math.round(Math.random() * 9);

so is the textfields

TextAreas = FirstTextBox;
TextAreas[i+1] = SecondTextBox;
TextAreas[i+2] = ThirdTextBox;

then ive got if statements like

if(e.getActionCommand().equals("0")){

if (RandomNumber == 0){
TextAreas.setText(String.valueOf("Correct...."));
i++;
}
else{
TextAreas.setText(String.valueOf("Incorrect, Try Again"));
}

but the integer i keeps getting reset to zero, how would i stop this?
(If the guess is correct, 1 should be added to the value i, so that it then uses the next random number and the next textfield)

please help

Posted: Tue Mar 25, 2003 10:14 am
by Guest
declare int i = 0 outside the actionperformed method, and declare it public

Posted: Fri Mar 28, 2003 4:51 pm
by jeffy
Anonymous wrote:declare int i = 0 outside the actionperformed method, and declare it public
Or declare the variable as static. :D