Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am working on a small text-based game in Java. I am trying to understand the concept of how to color the output without needing to use JNI. C++ has the ability to modify the console directly and also make system calls but as far as I can tell JAVA doesn't because of its ability to be system independent.

Is this possible or should I look at using a JFrame and the paint object?

share|improve this question
    
If you rely on a JFrame, then that will provide you with more consistency, but this will likely be a little bit more work. I've been working on a JComponent class which I call JScreen, but I haven't got ANSI support in there yet. Unfortunately it's going to be quite some time before I release this for download, but you could start out with a JTable (one column, multiple rows) and write your own internal println() method that handles scrolling and colours (you may even be able to use HTML "font" tags to make the colours appear). –  Randolf Richardson Jun 22 '11 at 3:37

1 Answer 1

up vote 1 down vote accepted

http://stackoverflow.com/questions/1448858/how-to-color-system-out-println-output is a answer to your question.

share|improve this answer
1  
The question is wrong. ANSI escape codes work fine in Java. It may be that their terminal wasn't set up right? –  munificent Jun 22 '11 at 2:22
    
@munificent: There were some issues with ANSI output from Java in the very early days, but as I recall this got resolved long before Swing/JFC was introduced. You're right that current versions support it just fine (+1) as I've experimented with this once and can confirm that it does indeed work. The only challenge might be MS-Windows, for which XP at least (and possibly Vista and Windows 7 also) don't have ANSI support at the DOS prompt by default. Most of the other systems should be okay though. –  Randolf Richardson Jun 22 '11 at 3:35
3  
@munificent Your post pointed me to this jansi.fusesource.org which is a small library to include to get the windows CMD window to handle ascii escape commands. –  Jeremy Hajek Jun 22 '11 at 19:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.