使用什么技术来设计我的 Java 程序的样式?



我正在尝试创建一个简单的Java程序。现在它只需要并显示用户输入。由于我对这种语言很陌生,我想知道如何设置程序样式以使其看起来对用户更具吸引力?我试图用谷歌搜索它,但我开始认为不可能为 java 程序设置样式...... 我正在使用日食工作区并创建新的.java文件

这是我的程序代码:

import java.util.Scanner;
public class Hello {
public static void main(String[] args) {          
Scanner input = new Scanner(System.in);
System.out.print("Enter an integer: ");
int number = input.nextInt();
System.out.println("You entered " + number);
}
}

那么,如何设置我的程序样式呢?也许我可以以某种方式使用 css 进行样式设置(例如,为文本添加大小、字体、创建按钮并更改其颜色(?还是其他技术?如何加入爪哇蚂蚁风格?

If your terminal supports it, you can use ANSI escape codes to use color in your output. It generally works for Unix shell prompts; however, it doesn't work for Windows Command Prompt (Although, it does work for Cygwin). For example, you could define constants like these for the colors:
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";
Then, you could reference those as necessary.
For example, using the above constants, you could make the following red text output on supported terminals:
System.out.println(ANSI_RED + "This text is red!" + ANSI_RESET);
You might want to check out the Jansi library. It provides an API and has support for Windows using JNI. I haven't tried it yet; however, it looks promising.
Also, if you wish to change the background color of the text to a different color, you could try the following as well:
public static final String ANSI_BLACK_BACKGROUND = "u001B[40m";
public static final String ANSI_RED_BACKGROUND = "u001B[41m";
public static final String ANSI_GREEN_BACKGROUND = "u001B[42m";
public static final String ANSI_YELLOW_BACKGROUND = "u001B[43m";
public static final String ANSI_BLUE_BACKGROUND = "u001B[44m";
public static final String ANSI_PURPLE_BACKGROUND = "u001B[45m";
public static final String ANSI_CYAN_BACKGROUND = "u001B[46m";
public static final String ANSI_WHITE_BACKGROUND = "u001B[47m";
For instance -
System.out.println(ANSI_GREEN_BACKGROUND + "This text has a green background but default text!" + ANSI_RESET);
System.out.println(ANSI_RED + "This text has red text but a default background!" + ANSI_RESET);
System.out.println(ANSI_GREEN_BACKGROUND + ANSI_RED + "This text has a green background and red text!" + ANSI_RESET);

最新更新