-
Notifications
You must be signed in to change notification settings - Fork 1
/
ArrayTableDataDemo.java
42 lines (35 loc) · 1.07 KB
/
ArrayTableDataDemo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.fr.data;
public class ArrayTableDataDemo extends AbstractTableData {
/**
* Define a String array for column names and a two-dimensional array to store data
*/
private String[] columnNames;
private Object[][] rowData;
/**
* Prepare data in the constructor.
*/
public ArrayTableDataDemo() {
String[] columnNames = {"Name", "Score"};
Object[][] datas = {{"Alex", 15},
{"Helly", 22}, {"Bobby", 99}};
this.columnNames = columnNames;
this.rowData = datas;
}
// Since hasRow() has been implemented in AbstractTableData, here we only need to implement the other four functions.
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public String getColumnName(int columnIndex) {
return columnNames[columnIndex];
}
@Override
public int getRowCount() {
return rowData.length;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
return rowData[rowIndex][columnIndex];
}
}