How to Change Color of Text in Java

This is the simple java program that changes the color of the text in the console. You can change the color of any line and can also use multiple colors in a single program.

Source Code 


package packaga.sixteen;
/**
 *
 * @author Shan
 */
public class color {
/**
     * @param args the command line arguments
     */
public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_BLACK = "\u001B[30m";
public static final String ANSI_RED = "\u001B[31m";
public static final String ANSI_GREEN = "\u001B[32m";
public static final String ANSI_YELLOW = "\u001B[33m";
public static final String ANSI_BLUE = "\u001B[34m";
public static final String ANSI_PURPLE = "\u001B[35m";
public static final String ANSI_CYAN = "\u001B[36m";
public static final String ANSI_WHITE = "\u001B[37m";
public static void main(String[] args) {
System.out.println(ANSI_YELLOW + "This text is yellow!" + ANSI_RESET);
System.out.println(ANSI_RED + "This text is red!" + ANSI_RESET);
System.out.println(ANSI_BLUE + "This text is blue!" + ANSI_RESET);
System.out.println(ANSI_PURPLE + "This text is purple!" + ANSI_RESET);
System.out.println("This text is reseted!");
}
}


Output of the Program


How to change color of text in java



Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment