How to use
C-Screen
Box-window and normal char
Components
download here: https://github.com/soybean15/CScreen/releases
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 framelike 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
setWidth(int width) - setting width of rectangular border of list. If not set, it will base on the longest size of the String inside the list.
setTitle(String title,Position pos) - Add title on the list, there are three available positions
Position.START, Position.CENTER, Position.END
.addItem(String item) - add item on the list.
getItem(int index) - get item on the list by index.
remove(int index) - remove item on the list by index.
set(int index, String item) - edit/update 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"};
CTable table = new CTable(header);//can also add 2d array/list on argument ex: new CTable(your2dArrayOrList, 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 qtyTotal = table.getIntTotal(2);
//get total of fourth column in float
float priceTotal = table.getFloatTotal(3);
System.out.println("Total Qty:"+qtyTotal);
System.out.println("Total Price:"+priceTotal);
Sample output:
CTable Functions
addList(List<List> arr) - Add 2d array on CTable.
addRow(String[] row) - Add row inside the table.
getRow(int index) - get all the value of selected row, index is the position of desired row.
getColumn(int index) - get all the value of selected column, index is the position of desired column.
removeRow(int index) - remove selected row by index
getCell(int row, int column) - get 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 int total value of a column
getFloatTotal(int columnIndex) - get float total value of a column
findRows(int column, String text) - find multiple rows inside the table.
ex List<List<String>> findRows = tableName.findRows(column, "item to search");
Hope you like it..enjoy.