|
|
|
|
@ -0,0 +1,58 @@
|
|
|
|
|
package flowershop.view;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import javax.swing.table.AbstractTableModel;
|
|
|
|
|
import flowershop.model.Flower;
|
|
|
|
|
|
|
|
|
|
//商品列表表格模型
|
|
|
|
|
public class FlowerTableModel extends AbstractTableModel{
|
|
|
|
|
|
|
|
|
|
//表格列表columnNames
|
|
|
|
|
private String[] columnNames = {"编号","花卉名","类别"};
|
|
|
|
|
|
|
|
|
|
private List<Flower> data = null;
|
|
|
|
|
|
|
|
|
|
public FlowerTableModel(List<Flower> data) {
|
|
|
|
|
this.data = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//返回行数
|
|
|
|
|
@Override
|
|
|
|
|
public int getRowCount() {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return data.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//返回列数
|
|
|
|
|
@Override
|
|
|
|
|
public int getColumnCount() {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return columnNames.length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获得某行某列的数据,而数据保存在对象数组data中
|
|
|
|
|
@Override
|
|
|
|
|
public Object getValueAt(int rowIndex, int columnIndex) {
|
|
|
|
|
|
|
|
|
|
// 每一行就是一个Product商品对象
|
|
|
|
|
Flower f = data.get(rowIndex);
|
|
|
|
|
|
|
|
|
|
switch(columnIndex) {
|
|
|
|
|
case 0 :
|
|
|
|
|
return f.getProductid();
|
|
|
|
|
|
|
|
|
|
case 1 :
|
|
|
|
|
return f.getName();
|
|
|
|
|
|
|
|
|
|
default :
|
|
|
|
|
return f.getCategory();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public String getColumnName(int columnIndex) {
|
|
|
|
|
return columnNames[columnIndex];
|
|
|
|
|
}
|
|
|
|
|
}
|