| | |
Turning my board from console to Message box
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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
Posts: 62
Reputation:
Solved Threads: 7
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
Java Syntax (Toggle Plain Text)
[ code ]leave out the spaces in the tags[ /code ]
Java Syntax (Toggle Plain Text)
[ 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.
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
Posts: 62
Reputation:
Solved Threads: 7
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: Nov 2007
Posts: 62
Reputation:
Solved Threads: 7
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.
![]() |
Other Threads in the Java Forum
- Previous Thread: Gridbag Layout Probelm [Code Included]
- Next Thread: compliler
Views: 1204 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for Java
911 addressbook android api append apple applet application arguments array arrays automation binary bluetooth character chat class classes client code component csv database detection draw eclipse error event exception file fractal ftp game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me japplet java javaarraylist javaprojects jmf jni jpanel julia linux list loop map method methods mobile netbeans newbie number object objects oracle oriented os panel print problem program programming project projects recursion replaydirector reporting researchinmotion return robot scanner score screen se server set size sms socket sort sql stream string swing test threads time transfer tree ubuntu windows






