Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Java HelloWorld set color

    How would I set a color to the text HelloWorld. My simpe script:

    Code:
    class HelloWorld {
    
    public static void main(String[] args) { 
    
     System.out.println("Hello world!");
    
    }
    
    }

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    I've never done colours in the console through java before. Though I think you could *probably* to it, it wouldn't be worth while, and it defeats the purpose of crossplatform independence. The AWT should have something that lets you hook into the OS commands, but I don't know if they are accessible for the programmer to manipulate.
    It would be easier to create a GUI that emulates a console window and apply text color to that. You can make it look and feel like a console window, but it would be cross platform which rocks.

    The problem with the consoles is that colours are platform dependent. Even with C you'd need to inspect you're environment, import the correct libraries and issue the proper commands.
    Consoles are such a pain, but as long as you're happy with the default background and colours that you use, they are way faster than a gui ever could be.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Gox
    Gox is offline
    Regular Coder Gox's Avatar
    Join Date
    May 2006
    Location
    Ontario, Canada
    Posts
    392
    Thanks
    2
    Thanked 20 Times in 20 Posts
    A quick google search led me to this page http://www.javaworld.com/javaworld/j...0-console.html

    It seems to do a good job of explaining why it's not possible to do this in the "traditional" sense, and provides a couple examples of using other libraries to "mimic" console text colour if it's something you really need.

    Personally, I don't feel that it's worth the effort for most cases.

  • #4
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can try some of ncurses library for java, but it will work under unix OS's and I'm not sure if there are ncurses library under win.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •