-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v2. Added features on Table and List
- Loading branch information
Showing
4 changed files
with
172 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,114 @@ | ||
import cscreen.classes.Position; | ||
|
||
import cscreen.classes.Symbol; | ||
import cscreen.components.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
|
||
|
||
public class Main { | ||
|
||
|
||
public static void main(String[] args) { | ||
|
||
List<List<String>> arr = new ArrayList<>(); | ||
arr.add(Arrays.asList("Marilyn Monroe", "21", "March", "1993")); | ||
arr.add(Arrays.asList("Robert De Niro", "22", "August", "1945")); | ||
arr.add(Arrays.asList("Malcolm X", "23", "June", "1944")); | ||
arr.add(Arrays.asList("Mohammad Ali", "24", "March", "1970")); | ||
Scanner sc = new Scanner(System.in); | ||
|
||
String[] header = {"Name", "Id", "Month", "Year"}; | ||
CTable table = new CTable(header, arr); | ||
table.addRow(new String[]{"Mike Tyson", "25", "April", ""}); | ||
table.display(); | ||
Screen screen = new Screen(20, 40, true);//20 rows, 40column, hasBorder | ||
screen.useBoxSet();//use box-window char | ||
screen.setTitle("Student Info"); | ||
|
||
//String[] header2 = {"Name","Id", "Month"}; | ||
CTable table2 = new CTable(null); | ||
table2.addList(arr); | ||
table2.useBoxSet(); | ||
table2.hasSeparator(true); | ||
Label label1 = new Label(4,3); | ||
label1.setText("FirstName:"); | ||
label1.place(screen); | ||
|
||
table2.addRow(new String[]{"Mike Tyson", "25", "April", "1980"}); | ||
TextBox txtFirstName = new TextBox(3,13); | ||
txtFirstName.setWidth(23); | ||
txtFirstName.place(screen); | ||
|
||
System.out.println(table2.getCell(0,0));//print marilyn | ||
table2.setCell(0,0,"Betty White");// change marilyn to betty | ||
table2.removeRow(1); // remove Robert De Niro | ||
table2.setAlignment(Position.CENTER); | ||
table2.display(); | ||
Label label2 = new Label(7,3); | ||
label2.setText("LastName:"); | ||
label2.place(screen); | ||
|
||
// String[] list1 = {"Banana", "Apple", "Potato", "Orange"}; | ||
// | ||
// CList cList1 = new CList(); | ||
// cList1.setTitle("Fruitserwerr",Position.CENTER); | ||
// | ||
// cList1.display(); | ||
// cList1.addItem("Strawberry"); | ||
// cList1.addItem("Dragon Fruit34234"); | ||
// | ||
// cList1.remove(0); | ||
// cList1.set(0,"Mango"); | ||
// cList1.display(); | ||
TextBox txtLastName = new TextBox(6,13); | ||
txtLastName.setWidth(23); | ||
txtLastName.place(screen); | ||
|
||
//System.out.println(cList1.getItem(0)); | ||
Label label3 = new Label(10,3); | ||
label3.setText("DOB:"); | ||
label3.place(screen); | ||
|
||
TextBox txtDOB = new TextBox(9,13); | ||
txtDOB.setWidth(23); | ||
txtDOB.place(screen); | ||
|
||
Label label4 = new Label(13,3); | ||
label4.setText("Age:"); | ||
label4.place(screen); | ||
|
||
TextBox txtAge = new TextBox(12,13); | ||
txtAge.setWidth(23); | ||
txtAge.place(screen); | ||
|
||
Label label5 = new Label(16,3); | ||
label5.setText("Course:"); | ||
label5.place(screen); | ||
|
||
TextBox txtCourse = new TextBox(15,13); | ||
txtCourse.setWidth(23); | ||
txtCourse.place(screen); | ||
|
||
screen.display(); | ||
|
||
CTable table = new CTable(new String[]{"Full Name","DOB","Age","Course"}); | ||
table.useBoxSet(); | ||
|
||
while (true){ | ||
//clear textBox | ||
txtFirstName.clear(); | ||
txtLastName.clear(); | ||
txtDOB.clear(); | ||
txtAge.clear(); | ||
txtCourse.clear(); | ||
|
||
System.out.println("FirstName:"); | ||
String firstname = sc.nextLine(); | ||
txtFirstName.setText(firstname); | ||
txtFirstName.place(screen); | ||
screen.display(); | ||
|
||
System.out.println("LastName:"); | ||
String lastname = sc.nextLine(); | ||
txtLastName.setText(lastname); | ||
txtLastName.place(screen); | ||
screen.display(); | ||
|
||
System.out.println("DOB:"); | ||
String dob = sc.nextLine(); | ||
txtDOB.setText(dob); | ||
txtDOB.place(screen); | ||
screen.display(); | ||
|
||
System.out.println("LastName:"); | ||
String age = sc.nextLine(); | ||
txtAge.setText(age); | ||
txtAge.place(screen); | ||
screen.display(); | ||
|
||
System.out.println("LastName:"); | ||
String course = sc.nextLine(); | ||
txtCourse.setText(course); | ||
txtCourse.place(screen); | ||
screen.display(); | ||
|
||
table.addRow(new String[]{firstname+" "+lastname,dob,age,course}); | ||
table.display(); | ||
|
||
|
||
|
||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters