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
|
package objetClient;
import java.awt.Component;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
public class ModeleDynObjetClient extends AbstractTableModel {
private final List<Client> tabClient = new ArrayList<Client>();
private final String[] entetes = {"No Client","Prénom", "Nom", "Adresse", "Code postal", "Ville"};
public ModeleDynObjetClient() {
super();
// remplissage temporaire
tabClient.add(new Client(001,"Albert", "Dupont", "1 rue de la paix",75008, "Paris"));
tabClient.add(new Client(002,"Michel", "Durand", "5 rue de la republique",59000, "Lille"));
tabClient.add(new Client(003,"Stephane", "Martin", "17 avenue Clemenceau",28000, "Chartres"));
tabClient.add(new Client(001,"Albert", "Dupont", "1 rue de la paix",75008, "Paris"));
tabClient.add(new Client(002,"Michel", "Durand", "5 rue de la republique",59000, "Lille"));
tabClient.add(new Client(003,"Stephane", "Martin", "17 avenue Clemenceau",28000, "Chartres"));
tabClient.add(new Client(001,"Albert", "Dupont", "1 rue de la paix",75008, "Paris"));
tabClient.add(new Client(002,"Michel", "Durand", "5 rue de la republique",59000, "Lille"));
tabClient.add(new Client(003,"Stephane", "Martin", "17 avenue Clemenceau",28000, "Chartres"));
tabClient.add(new Client(001,"Albert", "Dupont", "1 rue de la paix",75008, "Paris"));
tabClient.add(new Client(002,"Michel", "Durand", "5 rue de la republique",59000, "Lille"));
tabClient.add(new Client(003,"Stephane", "Martin", "17 avenue Clemenceau",28000, "Chartres"));
}
public int getRowCount() {
return tabClient.size();
}
public int getColumnCount() {
return entetes.length;
}
public String getColumnName(int columnIndex) {
return entetes[columnIndex];
}
public Object getValueAt(int rowIndex, int columnIndex) {
switch(columnIndex){
case 0:
return tabClient.get(rowIndex).getNumClient();
case 1:
return tabClient.get(rowIndex).getPrenom();
case 2:
return tabClient.get(rowIndex).getNom();
case 3:
return tabClient.get(rowIndex).getAdresse();
case 4:
return tabClient.get(rowIndex).getCodePostal();
case 5:
return tabClient.get(rowIndex).getVille();
default:
return null; //Ne devrait jamais arriver
}
}
public void addClient(Client client) {
tabClient.add(client);
fireTableRowsInserted(tabClient.size() -1, tabClient.size() -1);
}
public void removeClient(int rowIndex) {
tabClient.remove(rowIndex);
fireTableRowsDeleted(rowIndex, rowIndex);
}
} |
Partager