jav model
package org.hvbk.test.model;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.table.AbstractTableModel;
import org.hvbk.test.bean.Hocsinh;
import org.hvbk.test.bean.Khoavien;
import org.hvbk.util.DateUtil;
public class HocsinhModel {
public class DSHocsinhModel extends AbstractTableModel {
/**
*
*/
private static final long serialVersionUID = 1L;
private List<Hocsinh> hocsinhList = null;
private final String[] header = { "STT", "Mã số HS", "H� tên H�c sinh",
"Ngà y sinh" };
public List<Hocsinh> getHocsinhList() {
return hocsinhList;
}
public void setHocsinhList(List<Hocsinh> hocsinhList) {
this.hocsinhList = hocsinhList;
fireTableDataChanged();
}
public void addHocsinh(Hocsinh item) {
this.hocsinhList.add(item);
fireTableDataChanged();
}
public void removeHocsinh(int index) {
this.hocsinhList.remove(index);
fireTableDataChanged();
}
@Override
public Class<?> getColumnClass(int columnIndex) {
// TODO Auto-generated method stub
switch (columnIndex) {
case 0:
return Integer.class;
case 1:
return String.class;
case 2:
return String.class;
default:
return String.class;
}
}
@Override
public int getColumnCount() {
// TODO Auto-generated method stub
return header.length;
}
@Override
public String getColumnName(int columnIndex) {
// TODO Auto-generated method stub
return header[columnIndex];
}
@Override
public int getRowCount() {
// TODO Auto-generated method stub
return hocsinhList == null ? 0 : hocsinhList.size();
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
// TODO Auto-generated method stub
Hocsinh item = hocsinhList.get(rowIndex);
switch (columnIndex) {
case 0:
return rowIndex + 1;
case 1:
return item.getMaso();
case 2:
return item.getHo() + " " + item.getTen();
case 3:
return DateUtil.dateToString(item.getNgaysinh());
default:
return "";
}
}
}
public class KhoavienModel extends DefaultComboBoxModel {
/**
*
*/
private static final long serialVersionUID = 1L;
private List<Khoavien> khoavienList = null;
public List<Khoavien> getKhoavienList() {
return khoavienList;
}
public void setKhoavienList(List<Khoavien> khoavienList) {
this.khoavienList = khoavienList;
}
@Override
public Object getElementAt(int index) {
// TODO Auto-generated method stub
Khoavien item = khoavienList.get(index);
return item.getTenkhoa();
}
@Override
public int getIndexOf(Object anObject) {
// TODO Auto-generated method stub
Khoavien item = (Khoavien) anObject;
for (int i = 0; i < khoavienList.size(); i++) {
Khoavien o = khoavienList.get(i);
if (o.getMakhoa().equalsIgnoreCase(item.getMakhoa())) {
return i;
}
}
return 0;
}
@Override
public int getSize() {
// TODO Auto-generated method stub
return khoavienList == null ? 0 : khoavienList.size();
}
}
}
Bạn đang đọc truyện trên: Truyen247.Pro