How to use
C-Screen
Box-window and normal char
Components
If you use Maven or Gradle, add the following configuration to your project's pom.xml
| build.gradle
Be sure to replace the VERSION key below with the one of the versions shown above
<dependencies>
<!-- other dependencies are there -->
<dependency>
<groupId>tech.araopj</groupId>
<artifactId>cscreen</artifactId>
<version>VERSION</version>
</dependency>
<!-- other dependencies are there -->
</dependencies>
compile group: 'tech.araopj', name: 'cscreen', version: 'VERSION'
step1: download jar file on this link.
download here: https://github.com/soybean15/CScreen/releases/latest
step2: Add jar file on your project.
step3: Import the library. import cscreen.components.*;
step4: Finally create your first console UI. Enjoy!
C-screen is a text-base UI library on java console, you can now easily design your console program using c-screen with the help of cscreen components.
Update as of August 4, 2022, 1:20pm
Since Box-window is not working on default on some OS, I added a method where you can choose between normal character and box-window character
Normal Characters:
//normal character
Screen screen=new Screen(20,40,true);
//screen.useBoxSet();
screen.addTitle("Sample Screen",Position.START);
screen.display();
/*
sample output
+--------------------------------------+
|Sample Screen |
|+------------------------------------+|
*/
Box-Window Characters:
//box-window character
Screen screen = new Screen(20,40,true);
screen.useBoxSet();
screen.addTitle("Sample Screen",Position.START);
screen.display();
/*
sample output
╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮
│Sample Screen │
│╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮│
*/
1. Screen: a frame-like interface where you can put multiple components.
Sample code:
Screen screen = new Screen(20,40,true);
screen.addTitle("Sample Screen",Position.START);
screen.display();
/*the 3 parameters on the constructor are the following:
-width - width of screen
-height - height of screen
-hasBorder - add inner border if true
*/
Sample output:
2. Box: a rectangular component you can Put inside the Screen.
Sample code:
Screen screen=new Screen(20,40,true);
screen.addTitle("Sample Screen",Position.START);
Box box=new Box(3,3);
box.setHeight(5);
box.setWidth(30);
//place component inside the screen
box.place(screen);
//display screen
screen.display();
Sample output:
3.TextBox: A box component with text inside
Sample code:
Screen screen=new Screen(20,40,true);
screen.addTitle("Sample Screen",Position.START);
TextBox textBox=new TextBox(3,3);
textBox.setText("Sample text");
textBox.setHeight(5);
textBox.setWidth(30);
//place component inside the screen
textBox.place(screen);
//display screen
screen.display();
Sample output:
4. Label : Text you can put inside the screen.
Sample code:
Screen screen=new Screen(20,40,true);
screen.addTitle("Sample Screen",Position.START);
Label label=new Label(3,3);
label.setText("Sample Label");
//place component inside the screen
label.place(screen);
//display screen
screen.display();
Sample output:
5. Button: Buttonlike component which is good to have if you have multiple option in your code.
Sample code:
Screen screen=new Screen(20,40,true);
screen.addTitle("Sample Screen",Position.START);
Button button1=new Button(3,3);
button1.setText("Button1");
//place component inside the screen
button1.place(screen);
Button button2=new Button(6,3,"Button2");
//place component inside the screen
button2.place(screen);
//display screen
screen.display();
Sample output:
CList: component to help your list looks more presentable
Sample code:
CList list=new CList();
list.useBoxSet();
list.setWidth(20);
list.setTitle("Fruits",Position.CENTER);
list.addItem("Apple");
list.addItem("Banana");
list.addItem("Mango");
list.addItem("Banana");
list.display();
Sample output:
CList Functions
Function | Description |
---|---|
setWidth(int width) |
Set the width of the rectangular border of the list. If not set, it will be based on the longest size of the String inside the list. |
setTitle(String title, Position pos) |
Add a title to the list with three available positions: Position.START , Position.CENTER , Position.END . |
addItem(String item) |
Add an item to the list. |
getItem(int index) |
Get an item from the list by index. |
remove(int index) |
Remove an item from the list by index. |
set(int index, String item) |
Edit/update an item by index. |
CTable: easiest way to output your data on console, just pass your 2d array and you got yourself a neat and instant table.
Sample code:
String[]header={"Id","Product Name","Quantity","Price"};
//can also add 2d array/list on argument ex: new CTable(your2dArrayOrList, Header);
CTable table=new CTable(header);
table.useBoxSet();
table.hasSeparator(true);
//add row
table.addRow("f011","Fries","10","70.00");
table.addRow("b212","Burger","10","30.00");
table.addRow("fc11","Fried Chicken","10","110.50");
table.addRow("f011","Fries","10","70.00");
table.addRow("s930","Sundae","10","30.00");
//center third column
table.setColumnAlignment(2,Position.CENTER);
//Aligned End fourth column
table.setColumnAlignment(3,Position.END);
//print table
table.display();
//get total of third column in int
int quantityTotal=table.getIntTotal(2);
//get total of fourth column in float
float priceTotal=table.getFloatTotal(3);
System.out.println("Total Qty: "+quantityTotal);
System.out.println("Total Price: "+priceTotal);
Sample output:
CTable Functions
Function | Description |
---|---|
addList(List<List<String>> arr) |
Add 2D array to CTable. |
addRow(String[] row) |
Add a row inside the table. |
getRow(int index) |
Get all the values of the selected row; index is the position of the desired row. |
getColumn(int index) |
Get all the values of the selected column; index is the position of the desired column. |
removeRow(int index) |
Remove the selected row by index. |
getCell(int row, int column) |
Get the cell item inside the table. |
setCell(int row, int column, String str) |
Edit/update the selected cell in the table. |
setColumnAlignment(int columnIndex, Position position) |
Set column position by column index. Positions available: Position.START , Position.CENTER , Position.END . |
getIntTotal(int columnIndex) |
Get the integer total value of a column. |
getFloatTotal(int columnIndex) |
Get the float total value of a column. |
findRows(int column, String text) |
Find multiple rows inside the table. Example: List<List<String>> findRows = tableName.findRows(column, "item to search"); . |
Hope you like it..enjoy.