Forums Register Login

Tic Tac Toe Does not react

+Pie Number of slices to send: Send
Hi all,

this is what I clobbered together for the O'Reilly Java 2 Course, final assignment. There may well be several issues still with this code, my main grief at the moment is: The mouseReleased does not react (it did in the assignment I lifted it from and made only minor changes). No matter where I click on the grid, nothing happens.

Could someone please give me a hint what to do? Thanks in advance, and this is the code:








I have a hunch the mouseAdapter in TicTacBox is not correct, but it's just a hunch.
+Pie Number of slices to send: Send
You're not using it as a MouseListener. Line 121 of TicTacToe would apparently add that, but it's commented out.

Be aware that both ClickableBox and TicTacBox define the method mouseReleased, without the subclasss referencing the method in the superclass, so ClickableBox.mouseReleased will never be executed.
+Pie Number of slices to send: Send
Thanks Ulf, I thought it would be something simple... ARGH! OK; I corrected this, now I have the problem that the counter is not passed on and every click I make generates an "Ö". Oh well... Back to coding. Again, hints are appreciated.
1
+Pie Number of slices to send: Send
I think in line 232 you want "} else if (...) {". As it is, the first "if" increments the counter from 1 to 2, and then the second "if" kicks in immediately, and sets it back to 1.
+Pie Number of slices to send: Send
Thanks again, that generated a result I can tackle!
+Pie Number of slices to send: Send
OK, I edited the TicTacBox Class and the TicTacToe class as such (the clickable box is still the same as above):






If you try it, you see it sort of works, but I have to click a box twice for the O to appear and there will always be an X first. I have been unable to correct this. Any hints? (I know there are a few more flaws, but this is my main concern at the moment).

+Pie Number of slices to send: Send
Lines 53-58 of TicTacBox seem to implement exactly the behavior you describe (click one -> X, click again -> O). So if something else should happen, that looks like a starting point.
+Pie Number of slices to send: Send
OK, I solved all the other issues (like the faulty gameLogic() method), but all attempts to get the program to draw Xs and Os alternately into different boxes have failed (I also experimented with an instantiated TicTacToe in the TicTacBox Class and a few other things.

So I am actually asking for some concrete code now, since I am really stuck. Oh the shame!
+Pie Number of slices to send: Send
You have logic to alternate drawing X and O so if it isn't alternating correctly, the counter value must not be changing correctly. I suggest you add some print statements to the code that sets the counter value to see how it is being changed.
+Pie Number of slices to send: Send
Thanks, I sorted the problem already :-)
Alas, poor Yorick, he knew this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1207 times.
Similar Threads
Buttons...
Drawing Problems with JPanel /Jframe need optimize solution.
cannot find symbol
NullPointerException
Changes to Tic Tac Toe Game?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:55:19.