• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tic tac Toe GUI not displaying winner  RSS feed

 
Brad Siloya
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
130 lines. So I'm trying to get this game to display a winner or tie at the end of the game by using JOptionPane.showMessageDialog (lines 65 to 75) but it does nothing. I get no error code when I run it, and can play the board, but it doesn't end or display the popup. The only error I have is line 67 which is unnecessary for the code to work anyway. (or at least i think so) and line 77 shows unreachable statement yet line 90 has no issues . Any ideas what I'm doing wrong or how to make it work? games.board is after the first code which is a source file.



Board.java


Cell.java


Player.java


Mark.java


Outcome.java
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brad Siloya wrote:130 lines. So I'm trying to get this game to display a winner or tie at the end of the game by using JOptionPane.showMessageDialog (lines 65 to 75) but it does nothing. I get no error code when I run it, and can play the board, but it doesn't end or display the popup. The only error I have is line 67 which is unnecessary for the code to work anyway. (or at least i think so) and line 77 shows unreachable statement yet line 90 has no issues . Any ideas what I'm doing wrong or how to make it work? games.board is after the first code which is a source file.


When you say you get an error on line 67 what do you mean? You need to be a little more precise than that. If you're getting a compilation error then that definitely does matter and will stop all of the code from working. If its not a compilation error then what is it?

Incidentally, line 67 definitely does not look right for a for loop. What are you trying to do there?

Another error that I see in the getOutcome() method is that you have created a getOutcome variable and set it to null (line 61). At no point that I can see do you ever set a meaningful value to that variable, and certainly you are using it in comparisons while it is still null. Your code deciding which messages to display is comparing it to enums, and those comparisons will always be false.

Another thing I would comment on is that you have if statements that do not use curly braces. This is a very bad thing to do, and is very likely to confuse you. you should never miss out the curly braces, even if the compiler let's you.

Now the general way to fix problems like yours is to watch exactly what your program is doing, either by stepping through the code in a debugger or by putting System.out.printLine() statements in your code. In your case I would suggest that once you have addressed the compilation errors that you add some print statements so you can see exactly which lines of code are running and what value things have.

 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You should always format your code correctly; we have some suggestions here. If you don't indent your code, you can hide all sorts of errors from yourself. I have my own suggestions: use a decent text editor (not MS Notepad) and write backwards. If you go backwards into the {} you will get the indentation right.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!