-
Notifications
You must be signed in to change notification settings - Fork 0
/
SmartphoneTableModel.java
95 lines (82 loc) · 2.32 KB
/
SmartphoneTableModel.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
package ecommerceGUI;
import java.util.List;
import javax.swing.table.AbstractTableModel;
public class SmartphoneTableModel extends AbstractTableModel
{
static final int OBJECT_COL = -1;
static final int PRODUCTID_COL = 0;
static final int TITLE_COL = 1;
static final int DESCRIPTIONs_COL = 2;
static final int SCREEN_COL = 3;
static final int CAMERA_COL = 4;
static final int MANUFACTUREs_COL = 5;
static final int SHIPPINGs_COL = 6;
static final int QUANTITY_COL = 7;
static final int PRICING_COL = 8;
static final int CATEGORIES_COL = 9;
private String [] columnNames = {"ProductId", "Title", "Descriptions", "Screen", "Camera", "Manufacture", "Shippings", "Quantity", "Pricing", "Categories"};
private List <Smartphone> smartphones;
//constructor
public SmartphoneTableModel(){
}
public SmartphoneTableModel(List<Smartphone> theSmartphones){
smartphones = theSmartphones;
}
/*Override 5 methods below:-
1.getRowCount()
2.getColumnCount()
3.getColumnName(int col)
4.getColumnClass(int col) => does not need like MySQL
5.getValueAt(int row, int col)
*/
@Override
public int getRowCount()
{
return smartphones.size();
}
@Override
public int getColumnCount()
{
return columnNames.length;
}
@Override
public String getColumnName(int col) {
return columnNames[col];
}
// @Override
// public Class getColumnClass(int c) {
// return getValueAt(0, c).getClass();
// }
// this method is called to set the value of each cell
@Override
public Object getValueAt(int row, int col)
{
Smartphone tempSmartphone = smartphones.get(row);
switch (col){
case PRODUCTID_COL:
return tempSmartphone.getProductId();
case TITLE_COL:
return tempSmartphone.getTitle();
case DESCRIPTIONs_COL:
return tempSmartphone.getDescriptions();
case SCREEN_COL:
return tempSmartphone.getScreen();
case CAMERA_COL:
return tempSmartphone.getCamera();
case MANUFACTUREs_COL:
return tempSmartphone.getManufacture_details();
case SHIPPINGs_COL:
return tempSmartphone.getShipping_details();
case QUANTITY_COL:
return tempSmartphone.getQuantity();
case PRICING_COL:
return tempSmartphone.getPricing();
case CATEGORIES_COL:
return tempSmartphone.getCategories();
case OBJECT_COL:
return tempSmartphone.getObjId();
default:
return tempSmartphone;
}
}
}