You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.7 KiB
62 lines
1.7 KiB
package view;
|
|
|
|
import java.util.List;
|
|
|
|
import javax.swing.table.AbstractTableModel;
|
|
|
|
import domain.Dishwcy;
|
|
|
|
public class DishTableModelwcy extends AbstractTableModel {
|
|
//表格列名columnNames
|
|
private String[] columnNames = {"商品编号","商品类型","商品中文名"};
|
|
//表格中的内容保存在List<Dish>集合中
|
|
private List<Dishwcy> dishs = null;
|
|
public DishTableModelwcy(List<Dishwcy> dishs) {
|
|
this.dishs=dishs;
|
|
}
|
|
|
|
//返回行数
|
|
@Override
|
|
//重写了 getRowCount 方法,返回表格的行数,即 dishs 列表的大小。
|
|
public int getRowCount() {
|
|
// TODO 自动生成的方法存根
|
|
return dishs.size();
|
|
}
|
|
|
|
//返回列数
|
|
@Override
|
|
//重写了 getColumnCount 方法,返回表格的列数,即 columnNames 数组的长度。
|
|
public int getColumnCount() {
|
|
// TODO 自动生成的方法存根
|
|
return columnNames.length;
|
|
}
|
|
|
|
@Override
|
|
//重写了 getValueAt 方法,根据给定的行索引和列索引返回单元格的值。使用 switch 语句根据列索引返回相应的 Dishwcy 对象的属性值
|
|
public Object getValueAt(int rowIndex, int columnIndex) {
|
|
// TODO 自动生成的方法存根
|
|
// 每一行就是一个Dish商品对象
|
|
Dishwcy p = dishs.get(rowIndex);
|
|
|
|
switch(columnIndex) {
|
|
case 0:
|
|
return p.getDishid();// 第一列商品编号
|
|
case 1:
|
|
return p.getCategory();// 第二列商品编号
|
|
case 2:
|
|
return p.getCname();// 第三列商品编号
|
|
//default:
|
|
//return p.getEname();
|
|
|
|
|
|
}
|
|
return p;
|
|
|
|
}
|
|
//定义了 getColumnName 方法,根据列索引返回列名。
|
|
public String getColumnName(int columnIndex) {
|
|
return columnNames[columnIndex];
|
|
}
|
|
|
|
}
|