GUI game ... help

Using the Java SDK with TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Guest

GUI game ... help

Post 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
Guest

Post by Guest »

declare int i = 0 outside the actionperformed method, and declare it public
User avatar
jeffy
Posts: 323
Joined: Mon Mar 03, 2003 9:04 am
Location: Philadelphia

Post by jeffy »

Anonymous wrote:declare int i = 0 outside the actionperformed method, and declare it public
Or declare the variable as static. :D
Post Reply