•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 455,985 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,801 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 732 | Replies: 6 | Solved
![]() |
•
•
Join Date: Aug 2007
Location: Cherryville, NC
Posts: 34
Reputation:
Rep Power: 2
Solved Threads: 0
My tic tac toe board is done, but I need it to show up in the Dialog box, not the console, how would I do that?
Here is my code:
javax.swing.JOptionPane.showMessageDialog(null, "\n-------");
for (int i = 0; i < 3; i++) {
System.out.print("| ");
for (int j = 0; j < 3; j++)
System.out.print(spot[i][j] + " | ");
javax.swing.JOptionPane.showMessageDialog(null, "\n--------");
Here is my code:
javax.swing.JOptionPane.showMessageDialog(null, "\n-------");
for (int i = 0; i < 3; i++) {
System.out.print("| ");
for (int j = 0; j < 3; j++)
System.out.print(spot[i][j] + " | ");
javax.swing.JOptionPane.showMessageDialog(null, "\n--------");
•
•
Join Date: Nov 2007
Location: Belgium
Posts: 62
Reputation:
Rep Power: 1
Solved Threads: 6
Ok, I'm taking a look at it, but first you should know that when you post code, you should use the code tags like so: and when you're using a specific language like you did (i.e. Java) you use it like so:
Now, although I'm able to figure it out myself, you have one '{' and no '}' in your code. It's not because you're talking to humans instead of the compiler that you don't have to be correct anymore.
If your code and idea behind it wouldn't be that simple, it would be hard for us to know what you are really trying to do.
Others will appreciate it more when you follow rules like this and therefor will be more willing to help you out.
Black Box
[ code ]leave out the spaces in the tags[ /code ]
[ code=java ]leave out the spaces in the tags[ /code ]
Now, although I'm able to figure it out myself, you have one '{' and no '}' in your code. It's not because you're talking to humans instead of the compiler that you don't have to be correct anymore.
If your code and idea behind it wouldn't be that simple, it would be hard for us to know what you are really trying to do.Others will appreciate it more when you follow rules like this and therefor will be more willing to help you out.
Black Box
Last edited by Black Box : Dec 4th, 2007 at 3:07 am.
•
•
Join Date: Aug 2007
Location: Cherryville, NC
Posts: 34
Reputation:
Rep Power: 2
Solved Threads: 0
java Syntax (Toggle Plain Text)
javax.swing.JOptionPane.showMessageDialog(null, "\n-------"); for (int i = 0; i < 3; i++) { System.out.print("| "); for (int j = 0; j < 3; j++) System.out.print(spot[i][j] + " | "); javax.swing.JOptionPane.showMessageDialog(null, "\n--------"); }
I have the board, it works, but when I try making a messagebox instead of a console, I'm confused...
Last edited by Dio1080 : Dec 4th, 2007 at 3:10 am.
•
•
Join Date: Nov 2007
Location: Belgium
Posts: 62
Reputation:
Rep Power: 1
Solved Threads: 6
Ok, I'm assuming you want everything to appear in the message box. First of all, everything you give System.out.print, will be printed to your console, no matter what. The easiest way to get this done in your case is to do the following. Instead of printing what you want bit by bit to your messagebox, you should place it al in one string. So, don't use System.out.print, but use something like myString = myString + " | "; or something.
Then after your loops, you can create your messagebox and give your string to it as parameter.
That should pretty much do it. However, it seems that you're trying to work your way into Swing and I suggest you learn swing like it's supposed to be learned: from the beginning.
Black Box
Then after your loops, you can create your messagebox and give your string to it as parameter.
That should pretty much do it. However, it seems that you're trying to work your way into Swing and I suggest you learn swing like it's supposed to be learned: from the beginning.
Black Box
•
•
Join Date: Aug 2007
Location: Cherryville, NC
Posts: 34
Reputation:
Rep Power: 2
Solved Threads: 0
•
•
Join Date: Nov 2007
Location: Belgium
Posts: 62
Reputation:
Rep Power: 1
Solved Threads: 6
I can understand that you want to keep it simple, really, I think everyone wants everything to be simple. The thing is, diving head first in Swing and trying everything wrong, right and different until it works is:
1. a lot of work.
2. not going to teach you something because you won't know the exact reason why it works this time, but not any other time.
3. because of 1 & 2 a lot harder instead of simple...
So, either wait a bit with Swing, or try to put more time in it so you can learn it "the easy way".
Black Box
1. a lot of work.
2. not going to teach you something because you won't know the exact reason why it works this time, but not any other time.
3. because of 1 & 2 a lot harder instead of simple...
So, either wait a bit with Swing, or try to put more time in it so you can learn it "the easy way".
Black Box
Yes, moving your console app over to a Swing component isn't just a matter of stuffing the output into a message box. Message boxes don't work like the console at all. You will need to work with frames/panels and either arrays of components or custom 2D painting with mouse listeners.
It gets deep pretty quickly once you decide to move into GUI programming and as Black Box noted, you need to start at the beginning.
If you do go that route and get a bit of understanding of Swing under your belt, feel free to post back with questions on what components and techniques can be used to build your interface.
It gets deep pretty quickly once you decide to move into GUI programming and as Black Box noted, you need to start at the beginning.
If you do go that route and get a bit of understanding of Swing under your belt, feel free to post back with questions on what components and techniques can be used to build your interface.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Previous Thread: Gridbag Layout Probelm [Code Included]
- Next Thread: compliler



Linear Mode