The logic seems correct to me, but for some reason the program does not want to funtion properly, could you take a look at the program and give me some input, and I have a few variables not used in the program, even though they are defined because this is the part I need done in order to use those variables.
I would really appreciate the help on this one, its been bugging me for a few days now. [ June 05, 2008: Message edited by: James Mousseau ]
Through all the if statements, it should output an X first, then an O, but for some reason, its ONLY outputting X's through all the buttons (1-9), I added a system.out.print in there for the p1turn and p2turn, and p1turn seems to always add 2 to it, and stay at the value 3, but p2turn stays at 2, as if the p1turn = p1turn + 2, and the p2turn = p2turn + 2 dont seem to count, only counts once and to p1turn.
The program pretty much runs as its supposed to until it gets to:
I was just wondering if there is anything there I cant seem to notice, like brackets, where the "counter" (p1turn, p2turn) is placed.
And Id like to thank you guys for helping me out, im learning more and more everyday
In your program p1Turn, p2Turn, and turn are local variables declared in the actionPerformed() method. That means each time actionPerformed is called -- i.e., each time a button is pressed -- these variables are all recreated from scratch, and initialized to 1, 2, and 0, respectively. If you want those variables to persist between calls to this method -- and you do, since they represent the state of the game -- then they should be declared at class level, outside of any method. Then they are called instance variables, and they're initialized just once when an instance of your class is created.