User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Aug 2007
Location: Cherryville, NC
Posts: 34
Reputation: Dio1080 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Dio1080's Avatar
Dio1080 Dio1080 is offline Offline
Light Poster

Help Turning my board from console to Message box

  #1  
Dec 4th, 2007
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--------");
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Belgium
Posts: 62
Reputation: Black Box is on a distinguished road 
Rep Power: 1
Solved Threads: 6
Black Box Black Box is offline Offline
Junior Poster in Training

Re: Turning my board from console to Message box

  #2  
Dec 4th, 2007
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:
[ code ]leave out the spaces in the tags[ /code ]
and when you're using a specific language like you did (i.e. Java) you use it like so:
[ 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.
Reply With Quote  
Join Date: Aug 2007
Location: Cherryville, NC
Posts: 34
Reputation: Dio1080 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Dio1080's Avatar
Dio1080 Dio1080 is offline Offline
Light Poster

Help Re: Turning my board from console to Message box

  #3  
Dec 4th, 2007
  1.  
  2. javax.swing.JOptionPane.showMessageDialog(null, "\n-------");
  3.  
  4. for (int i = 0; i < 3; i++) {
  5. System.out.print("| ");
  6. for (int j = 0; j < 3; j++)
  7. System.out.print(spot[i][j] + " | ");
  8. javax.swing.JOptionPane.showMessageDialog(null, "\n--------");
  9. }

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.
Reply With Quote  
Join Date: Nov 2007
Location: Belgium
Posts: 62
Reputation: Black Box is on a distinguished road 
Rep Power: 1
Solved Threads: 6
Black Box Black Box is offline Offline
Junior Poster in Training

Re: Turning my board from console to Message box

  #4  
Dec 4th, 2007
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
Reply With Quote  
Join Date: Aug 2007
Location: Cherryville, NC
Posts: 34
Reputation: Dio1080 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Dio1080's Avatar
Dio1080 Dio1080 is offline Offline
Light Poster

Help Re: Turning my board from console to Message box

  #5  
Dec 4th, 2007
waoh woah woah, thanks for the help, but I like it simple, I only got to arrays in my book so, everything I did so far has been simple, nothing to advance, thats why I have about 3 to 4 pages of code.
Reply With Quote  
Join Date: Nov 2007
Location: Belgium
Posts: 62
Reputation: Black Box is on a distinguished road 
Rep Power: 1
Solved Threads: 6
Black Box Black Box is offline Offline
Junior Poster in Training

Re: Turning my board from console to Message box

  #6  
Dec 4th, 2007
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
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 3,076
Reputation: Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold 
Rep Power: 15
Solved Threads: 306
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Sensei

Re: Turning my board from console to Message box

  #7  
Dec 4th, 2007
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Java Forum

All times are GMT -4. The time now is 9:25 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC