-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItemsTable.java
More file actions
82 lines (63 loc) · 2.08 KB
/
Copy pathItemsTable.java
File metadata and controls
82 lines (63 loc) · 2.08 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;
public class ItemsTable extends AbstractTableModel
{
private String columnNames[]={"Product ID","Name","Category","Price(£)","No of available items","Info"};
ArrayList<Product> tableProductList;
public ItemsTable(ArrayList<Product> list)
{
tableProductList=list;
}
@Override
public int getRowCount() {
return tableProductList.size();
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public Object getValueAt(int row, int col) {
Object temp = null;
if (col == 0) {
temp = tableProductList.get(row).getProductID();
} else if (col == 1) {
temp = tableProductList.get(row).getProductName();
} else if (col == 2) {
temp = tableProductList.get(row).getClass().getSimpleName();
} else if (col == 3) {
temp = new Double(tableProductList.get(row).getPrice());
} else if (col == 4){
temp = tableProductList.get(row).getNoOfAvailableItem();
} else if (col == 5) {
Product product = tableProductList.get(row);
if (product instanceof Electronics) {
temp = ((Electronics) product).getBrandName() + ", " + ((Electronics) product).getWarrantyPeriod()+" months warranty";
} else if (product instanceof Clothing) {
temp = ((Clothing) product).getColour() + ", " + ((Clothing) product).getSize();
}
}
if (temp == null) {
temp="-";
}
return temp;
}
public String getColumnName(int col) {
return columnNames[col];
}
public Class getColumnClass(int col) {
if (col == 0) {
return Product.class;
} else if (col == 3) {
return Double.class;
} else if (col==4)
{
return int.class;
} else {
return String.class;
}
}
/*public void setBackgroundColor(JTable table,int row)
{
}*/
}