Results 1 to 8 of 8
- 06-10-2010, 03:25 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 6
- Rep Power
- 0
How to print words in different colours?
is it really possible?
like everyone knows, System.err.println("prints in red");
it prints in red
but
now theres one issue
if i use this
public class Testing {
public static void main(String[] args) {
System.out.println("Standard output Stream message");
System.err.println("Standard error stream message");
System.out.println("Standard output Stream message");
}
}
my output becomes
Standard output Stream message
Standard output Stream message
Standard error stream message
the err message goes all the way down...
so i googled about printing words in different colours and came across this import java.awt.Color;
but i don't know how to use it.
how can i print out words in different colours?
i'm using eclipse
- 06-10-2010, 03:28 PM #2
Member
- Join Date
- Jun 2010
- Posts
- 6
- Rep Power
- 0
sometimes, when i re run the code, the err.println line prints sometimes in these order:
Standard error stream message
Standard output Stream message
Standard output Stream message
Standard error stream messageStandard output Stream message
Standard output Stream message
Standard output Stream message
Standard error stream message
Standard output Stream message
it keeps jumping around! confused!!!
- 06-10-2010, 03:54 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
- 06-10-2010, 03:57 PM #4
Member
- Join Date
- Jun 2010
- Posts
- 6
- Rep Power
- 0
is it possible to manually print it out in a different colour?
using that import java.awt.Color; ?
- 06-10-2010, 04:28 PM #5
The import statement is an extension of the classpath used by the compiler to find a class definition. It does not generate any code. If you use a class that is in a package, you need to tell the compiler where it is. One way is to use the import statement. The other is to explicitly code the package path:
java.awt.Color aColor = java.awt.Color(Color.blue);
- 06-10-2010, 04:33 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
If you want to print in color on your terminal/console you don't need that awt.Color class. Each and every type of terminal has its own capabilities; some can't even print in differnt colors; if they can each and every terminal type has its own way to actually do that. Unix solved this issue by its termcap file or later its terminal database. Java can do it by using jcurses which is an ncurses clone.
Better use a Swing component for that purpose if possible.
kind regards,
Jos
- 06-10-2010, 04:48 PM #7
Member
- Join Date
- Jun 2010
- Posts
- 6
- Rep Power
- 0
how do i print out in that colour?Java Code:import java.awt.Color; public class FinalTry { public static void main(String[] args) { System.out.println("Standard output Stream message"); System.err.println("Standard error stream message"); System.out.println("Standard output Stream message"); java.awt.Color aColor = Color.blue; } }
PS: i'm trying to learn some "advance" stuff here...
i'm just few weeks in java...
can u show me an example on how to do it?Better use a Swing component for that purpose if possible.
please?
- 06-10-2010, 04:54 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
Using Swing components there are numerous ways to print text in a certain color; most of the components have a method that sets the foreground color. All text contained in the component will be printed in that particular color. Read some Swing tutorials and you'll see.
kind regards,
Jos
Similar Threads
-
Changing text fonts and colours for specific files.
By breako in forum EclipseReplies: 0Last Post: 01-27-2010, 03:52 PM -
Help: Num to words
By MyOnlineChurva in forum New To JavaReplies: 16Last Post: 01-08-2010, 01:41 AM -
PDFBOX change text colours and remove background
By gstkein in forum Advanced JavaReplies: 1Last Post: 11-20-2009, 11:54 AM -
Print the text file and print preview them
By Java Tip in forum java.awtReplies: 0Last Post: 06-22-2008, 11:04 PM -
help w words
By Gilgamesh in forum New To JavaReplies: 5Last Post: 11-21-2007, 06:15 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks