商业网站建设设计装饰,wordpress djiango,seo百度快照优化公司,深圳网站建设大概多少钱问题#xff1a;怎么样用System.out.println在控制台打印出颜色
怎么样才能在控制台里打印颜色啊#xff1f;我想要展示一些有颜色的字体#xff0c;当处理器发送数据和接收数据的时候#xff0c;也使用不同颜色的字体。
回答一
在这个Java类里面带有public static 的数…问题怎么样用System.out.println在控制台打印出颜色
怎么样才能在控制台里打印颜色啊我想要展示一些有颜色的字体当处理器发送数据和接收数据的时候也使用不同颜色的字体。
回答一
在这个Java类里面带有public static 的数据域里面有一系列的颜色。
用法
System.out.println(ConsoleColors.RED RED COLORED
ConsoleColors.RESET NORMAL);记住千万不要忘记在打印以后重置没有清理的话那个效果会一直保留的。
public class ConsoleColors {// Resetpublic static final String RESET \033[0m; // Text Reset// Regular Colorspublic static final String BLACK \033[0;30m; // BLACKpublic static final String RED \033[0;31m; // REDpublic static final String GREEN \033[0;32m; // GREENpublic static final String YELLOW \033[0;33m; // YELLOWpublic static final String BLUE \033[0;34m; // BLUEpublic static final String PURPLE \033[0;35m; // PURPLEpublic static final String CYAN \033[0;36m; // CYANpublic static final String WHITE \033[0;37m; // WHITE// Boldpublic static final String BLACK_BOLD \033[1;30m; // BLACKpublic static final String RED_BOLD \033[1;31m; // REDpublic static final String GREEN_BOLD \033[1;32m; // GREENpublic static final String YELLOW_BOLD \033[1;33m; // YELLOWpublic static final String BLUE_BOLD \033[1;34m; // BLUEpublic static final String PURPLE_BOLD \033[1;35m; // PURPLEpublic static final String CYAN_BOLD \033[1;36m; // CYANpublic static final String WHITE_BOLD \033[1;37m; // WHITE// Underlinepublic static final String BLACK_UNDERLINED \033[4;30m; // BLACKpublic static final String RED_UNDERLINED \033[4;31m; // REDpublic static final String GREEN_UNDERLINED \033[4;32m; // GREENpublic static final String YELLOW_UNDERLINED \033[4;33m; // YELLOWpublic static final String BLUE_UNDERLINED \033[4;34m; // BLUEpublic static final String PURPLE_UNDERLINED \033[4;35m; // PURPLEpublic static final String CYAN_UNDERLINED \033[4;36m; // CYANpublic static final String WHITE_UNDERLINED \033[4;37m; // WHITE// Backgroundpublic static final String BLACK_BACKGROUND \033[40m; // BLACKpublic static final String RED_BACKGROUND \033[41m; // REDpublic static final String GREEN_BACKGROUND \033[42m; // GREENpublic static final String YELLOW_BACKGROUND \033[43m; // YELLOWpublic static final String BLUE_BACKGROUND \033[44m; // BLUEpublic static final String PURPLE_BACKGROUND \033[45m; // PURPLEpublic static final String CYAN_BACKGROUND \033[46m; // CYANpublic static final String WHITE_BACKGROUND \033[47m; // WHITE// High Intensitypublic static final String BLACK_BRIGHT \033[0;90m; // BLACKpublic static final String RED_BRIGHT \033[0;91m; // REDpublic static final String GREEN_BRIGHT \033[0;92m; // GREENpublic static final String YELLOW_BRIGHT \033[0;93m; // YELLOWpublic static final String BLUE_BRIGHT \033[0;94m; // BLUEpublic static final String PURPLE_BRIGHT \033[0;95m; // PURPLEpublic static final String CYAN_BRIGHT \033[0;96m; // CYANpublic static final String WHITE_BRIGHT \033[0;97m; // WHITE// Bold High Intensitypublic static final String BLACK_BOLD_BRIGHT \033[1;90m; // BLACKpublic static final String RED_BOLD_BRIGHT \033[1;91m; // REDpublic static final String GREEN_BOLD_BRIGHT \033[1;92m; // GREENpublic static final String YELLOW_BOLD_BRIGHT \033[1;93m;// YELLOWpublic static final String BLUE_BOLD_BRIGHT \033[1;94m; // BLUEpublic static final String PURPLE_BOLD_BRIGHT \033[1;95m;// PURPLEpublic static final String CYAN_BOLD_BRIGHT \033[1;96m; // CYANpublic static final String WHITE_BOLD_BRIGHT \033[1;97m; // WHITE// High Intensity backgroundspublic static final String BLACK_BACKGROUND_BRIGHT \033[0;100m;// BLACKpublic static final String RED_BACKGROUND_BRIGHT \033[0;101m;// REDpublic static final String GREEN_BACKGROUND_BRIGHT \033[0;102m;// GREENpublic static final String YELLOW_BACKGROUND_BRIGHT \033[0;103m;// YELLOWpublic static final String BLUE_BACKGROUND_BRIGHT \033[0;104m;// BLUEpublic static final String PURPLE_BACKGROUND_BRIGHT \033[0;105m; // PURPLEpublic static final String CYAN_BACKGROUND_BRIGHT \033[0;106m; // CYANpublic static final String WHITE_BACKGROUND_BRIGHT \033[0;107m; // WHITE}回答二
使用颜色函数打印带有颜色的文本
代码:
enum Color {RED(\033[0;31m), // REDGREEN(\033[0;32m), // GREENYELLOW(\033[0;33m), // YELLOWBLUE(\033[0;34m), // BLUEMAGENTA(\033[0;35m), // MAGENTACYAN(\033[0;36m), // CYANprivate final String codeColor(String code) {this.code code;}OverrideString toString() {return code}
}def color { color, txt -def RESET_COLOR \033[0mreturn ${color}${txt}${RESET_COLOR}
}
用法:
test {println color(Color.CYAN, testing)
}文章翻译自Stack Overflowhttps://stackoverflow.com/questions/5762491/how-to-print-color-in-console-using-system-out-println