• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create a box around text in Java. Inside windows cmd.exe  RSS feed

 
Nick Prokhorov
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone!

I really need some help with some Java.



How can I make a box around text in Java which will appear in Windows cmd.exe?

Only using System.out.print("X"); and System.out.println("X"); . It MUST be a solid box and not use symbols like - or _ .

It can also use int X , double X, char X, String X, and boolean X.



Please explain it step by step. I'm a complete noob. :-)
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick Prokhorov wrote:Only using System.out.print("X"); and System.out.println("X"); . It MUST be a solid box and not use symbols like - or _ .

Sounds like a curses problem to me. There are typographic symbols available for doing this, and I suspect they're part of the Unicode standard; but whether they will display on all terminals, or indeed whether they're the same ones as recognised by cmd.exe, is an entirely different matter (this page would suggest not).

Whatever you come up with, I suspect it won't work on all platforms or terminals, which is one of the basic premises of Java; but if it's just for a school exercise, I'd start with the page I linked.

I'd also strongly suggest testing them out thoroughly before you start writing any "box drawing" logic.

Winston
 
Nick Prokhorov
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a ton for the reply!

I'm just not sure how to enter the ASCII characters into my program.

 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, first of all the box-drawing characters I think you're asking about aren't ASCII characters. (See http://www.asciitable.com/ for a list of the ASCII characters.) However that isn't really a problem because Java uses Unicode anyway, of which ASCII is only a tiny subset.

So you could find box-drawing characters in Unicode, but chances are that the console encoding which your machine uses doesn't recognize those characters, but instead is expecting some other box-drawing characters from some charset which doesn't match Unicode properly.

If you're completely baffled by what I just wrote, that confirms what I'm about to write, which is that drawing boxes on a Windows console isn't a suitable project for a Java newbie. In fact I'd go so far as to say it isn't a suitable project for any Java programmer because people haven't been writing console applications for years now.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!