• Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing a 2d array  RSS feed

 
Jim Venolia
Ranch Hand
Posts: 312
2
Chrome Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a 2d array of ascii chars that I want to display. For example, think of a chessboard with ' ' as an mt white square, '.' an mt black square, 'k' is a white king, 'K' a black king, etc. I have a 'char [][]' board = new char [8][8];'. I want to see:



How would you print this thing out? I'm trying to use JTextArea, but unfortunately it seems to treat the requested size as a suggestion and does it's own thing.

Note my app isn't chess related, and the size is determined at runtime based on the data.

My code is:




The problem is, instead of an 8x8 display, I'm getting a 2x50 display. Which really doesn't look like what I want.
 
Joel Christophel
Ranch Hand
Posts: 250
1
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should be more specific and post some code that can be compiled and executed. What do you mean by display? You could use System.out.print(), or do you want to specifically display it in a window using a JTextArea?

Also, when a chess piece is occupying a square, the square color is no longer being communicated, only the piece color. Why do you need to store square color anyway, as they are constant and unchanging?

Maybe this will help:

 
Jim Venolia
Ranch Hand
Posts: 312
2
Chrome Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You should be more specific and post some code that can be compiled and executed. What do you mean by display? You could use System.out.print(), or do you want to specifically display it in a window using a JTextArea?

Also, when a chess piece is occupying a square, the square color is the longer being communicated, only no piece color. Why do you need to store square color anyway, as they are constant and unchanging?


Point taken. I'm not writing a chess program, that just seemed like a good example. My app will parse a block of data, make a graphic representation stored in a 2D array, display it, parse a block, lather rinse repeat. If you want, think of it as showing all moves in a chess game.

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!