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
| import java.awt.Color;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
public class ModelDynamikObjets extends AbstractTableModel{
/**
*
*/
private static final long serialVersionUID = 1L;
private final ArrayList<Ami> amis=new ArrayList<Ami>();
private final String []entetes={"nom","prenom","couleur","homme","Sport"};
public ModelDynamikObjets(){
super();
amis.add(new Ami("ouf","confiseri",Color.RED,true,Sport.TENNIS));
amis.add(new Ami("bande","essai",Color.blue,false,Sport.NATATION));
amis.add(new Ami("only","java",Color.RED,true,Sport.TENNIS));
amis.add(new Ami("jtable","dynamik",Color.BLACK,true,Sport.FOOTBALL));
amis.add(new Ami("modele","test",Color.YELLOW,true,Sport.RIEN));
amis.add(new Ami("for","an",Color.BLACK,true,Sport.NATATION));
amis.add(new Ami("example","thanks",Color.RED,true,Sport.TENNIS));
}
@Override
public int getColumnCount() {
// TODO Auto-generated method stub
return entetes.length;
}
@Override
public int getRowCount() {
// TODO Auto-generated method stub
return amis.size();
}
@Override
public Object getValueAt(int rowindex, int ColumnIndex) {
// TODO Auto-generated method stub
switch (ColumnIndex) {
case 0:
return amis.get(rowindex).getNom();
case 1:
return amis.get(rowindex).getPrenom();
case 2:
return amis.get(rowindex).getCouleur();
case 3:
return amis.get(rowindex).isHomme();
case 4:
return amis.get(rowindex).getSport();
default:
return null;
} }
public String getColumnName(int ColumnIndex) {
return entetes[ColumnIndex];
}
public void addAmi(Ami ami){
amis.add(ami);
fireTableRowsInserted(amis.size()-1, amis.size()-1);
}
public void removeAmi(int RowIndex){
amis.remove(RowIndex);
fireTableRowsDeleted(RowIndex, RowIndex);
}}
Merci de m'indiquer ce qui manque a ce code |
Partager