mirror of
https://github.com/anas-elgarhy/JColorfulConsole.git
synced 2024-08-14 23:57:19 +00:00
Add examples
This commit is contained in:
parent
fb8ba71e67
commit
3cce7ba71e
6 changed files with 54 additions and 27 deletions
43
README.md
43
README.md
|
@ -43,6 +43,49 @@ allprojects {
|
|||
|
||||
## Usage:
|
||||
|
||||
```java
|
||||
public class Example1 {
|
||||
public static void main(String[] args) {
|
||||
ColoredString hello = new ColoredString("Hello, ");
|
||||
hello.setForegroundColor(TextColor.ANSI.BLUE); // Set text color to red
|
||||
hello.setBackgroundColor("magenta"); // Set background color to magenta
|
||||
hello.addStyle(TextStyle.BOLD); // Add bold style
|
||||
|
||||
ColoredString world = new ColoredString();
|
||||
world.setStr("World!"); // Set string to "World!"
|
||||
world.setForegroundColor("#542413"); // Set text color
|
||||
world.setBackgroundColor(new TextColor.RGB(34, 139, 34)); // Set background color
|
||||
world.addStyle(TextStyle.ITALIC); // Add italic style
|
||||
|
||||
System.out.print(hello); // Print colored string
|
||||
System.out.print(world); // Print colored string
|
||||
|
||||
}
|
||||
}
|
||||
```
|
||||

|
||||
|
||||
```java
|
||||
public class Example2 {
|
||||
public static void main(String[] args) {
|
||||
new Thread(() -> {
|
||||
while (true) {
|
||||
System.out.println(new ColoredString("Hi",
|
||||
new TextColor.RGB((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255)),
|
||||
new TextColor.RGB((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255)),
|
||||
TextStyle.values()[(int) (Math.random() * TextStyle.values().length)]));
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
```
|
||||

|
||||
|
||||
## Requirements for development:
|
||||
- Maven
|
||||
- jdk 17
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue