I'm trying to make a Tic Tac Toe game for my Java class. I am not able to use JButtons only JPanels. I'm stuck on the part where my program determines if there are 3 x's or o's in a row.

public void winner()
		if(3 = tictactoe[0].turn + tictactoe[1].turn + tictactoe[2].turn)

			System.out.println("X has won");



I had established turn as being a 1(x) or a 2(o). If 3 panels in a row [0] + [1] + [2] = 3 then it would mean that "x" had won. I need to add more to it to check all panels but I am getting errors just testing it. tictactoe[] are the panels 0-8. Turn is in the class "MousePart" which contains the MouseEvent. Three of the errors are that it cannot find the variable turn. I'm not sure how to establish it so it knows to go to MousePart. The Fourth error is unexpected type - probably being the 3 = tictactoe[]. I'm not sure what to do.

Recommended Answers

All 2 Replies

ok look at this pattern of arrays[row][column]
Case 1:
(hint] set a loop and if statement
[0][0],[0][1],[0,2] == win
[1][0],[1][1],[1,2] == win
[2][0],[2][1],[2,2] == win
Case 2:
(for loops and if statement)
[0][0],[1][0],[2,0] == win
[0][1],[1][1],[2,1] == win
[0][2],[1][2],[2,2] == win

Case 3:
no loops needed

hope that helps lol

If you post all your code, we can help you with the errors. Usually, the errors have a long explanation what they are, and on what line they occur. Check that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.