formatted printing of text- color

B

babo

I don't know how to use println with diferent color of text from
default and to print ascii of card signes, like hearts, spike, etc...


like: System.out.println("This text is RED, and this is BLUE")


Thnx
 
O

Oliver Wong

babo said:
I don't know how to use println with diferent color of text from
default and to print ascii of card signes, like hearts, spike, etc...


like: System.out.println("This text is RED, and this is BLUE")


Thnx

Colors are terminal specific (and thus OS specific (and thus probably
you won't find direct support for that within Java)). Try looking up ANSI as
a starting point.

For the card suits and things like that, you can probably find
appropriate symbols in Unicode, which Java fully supports.

- Oliver
 
Z

zero

I don't know how to use println with diferent color of text from
default and to print ascii of card signes, like hearts, spike, etc...


like: System.out.println("This text is RED, and this is BLUE")


Thnx

There currently is no way to change the colour of the output on the console
window.

There are no ascii heart or spike symbols, so that's out too.

You may want to look into using a Swing GUI with a JEditorPane.
 
B

babo

#include <stdio.h>
#include <conio.h>

int main () {
char i;

for (i=0;i<=102;i++)
{
printf ("\n%2c %4d",i,i);
}
getch ();
}
//this will print You a ascii hearts and spikes in the begining???and
then the letters
 
B

babo

#include <stdio.h>
#include <conio.h>

int main () {
char i;

for (i=0;i<=102;i++)
{
printf ("\n%2c %4d",i,i);
}
getch ();
}
//this will print You a ascii hearts and spikes in the begining???and
then the letters

//ofcourse in c language ...
 
Z

zero

#include <stdio.h>
#include <conio.h>

int main () {
char i;

for (i=0;i<=102;i++)
{
printf ("\n%2c %4d",i,i);
}
getch ();
}
//this will print You a ascii hearts and spikes in the begining???and
then the letters

//ofcourse in c language ...

This is because the first 32 ASCII characters are non-printing characters
such as tab, newline, backspace, escape, ... How these are represented
depends greatly on the implementation, the platform, and the platform's
settings. Try running this same C program before and after setting the
KEYB setting on DOS systems (I don't know if it still works on 32 bit
windows systems). You will get very different results.

You can see the complete ASCII table at http://www.asciitable.com/ Compare
the output from your code above to the table, and you will see that the
first 32 characters come out differently, but after that it should be the
same.

The bottom line is, you can't do what you want in ASCII code. Unicode
might help, but you're still not going to get the colours you mentioned in
your first post.

Why do you want this in the console window anyway? If you want something
that looks nice, you really need a GUI.
 
R

Roedy Green

I don't know how to use println with diferent color of text from
default and to print ascii of card signes, like hearts, spike, etc...

Consoles don't support colour. You have to create your own logging
window that supports colour.
 
J

Jeffrey Schwab

Roedy said:
Consoles don't support colour. You have to create your own logging
window that supports colour.

Most consoles do support color. The problem is that different consoles
support color in different ways. There are libraries that can shield
applications from the differences between different console interfaces.
A quick Google turns up this library, which I have not used:

http://sourceforge.net/projects/javacurses/

Alternatively, if the output is meant only for logging, it might be
easier to write some kind of rich text, e.g. HTML. If the output is to
be read in real-time, and color is absolutely necessary, Swing might be
the best option.
 
L

Luc The Perverse

babo said:
#include <stdio.h>
#include <conio.h>

int main () {
char i;

for (i=0;i<=102;i++)
{
printf ("\n%2c %4d",i,i);
}
getch ();
}
//this will print You a ascii hearts and spikes in the begining???and
then the letters

But . . . um . .that's not a java program :)
 
R

Roedy Green

Most consoles do support color.

Console as a special meaning in java. It does not just mean a log
display. It is implemented in a platform independent way, which is
why no colour.

It is surprisingly easy to write your own console log class that has
colour, timestamping, persistence etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top