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 83 84 85
| import java.util.Vector;
import javax.swing.table.AbstractTableModel;
import java.io.*;
import javax.swing.*;
import javax.swing.table.*;
import java.io.*;
import java.util.*;
public class Table extends AbstractTableModel {
public String element[][];
protected Vector columnNames ; //noms de colonnes
private int RowCount;
private int ColumnCount;
/**
* constructeur : on récupère le nom du fichier
* puis on initialise les deux Vectors en lisant le fichier
*/
public Table(String A[][],Vector columnNames, int ColumnCount,int RowCount) {
this.columnNames=columnNames;
this.element=A;
this.RowCount=RowCount;
this.ColumnCount=ColumnCount;
}
public Table(String A[][], int ColumnCount,int RowCount) {
this.element=A;
this.RowCount=RowCount;
this.ColumnCount=ColumnCount;
}
public Table() {
this.element=new String[RowCount][ColumnCount];
}
/**
* lignes
*/
public int getRowCount() {
return this.RowCount;
}
public void setRowCount(int RowCount) {
this.RowCount=RowCount;
}
/**
* colonnes
*/
public int getColumnCount() {
return this.ColumnCount;
}
public void setColumnCount(int ColumnCount) {
this.ColumnCount=ColumnCount;
}
/**
* possibilité d'édition des données
*/
public boolean isCellEditable(int rowIndex, int columnIndex) {
return true;
}
public String getColumnName(int columnIndex) {
String colName="";
if (columnIndex <= getColumnCount())
colName=(String)columnNames.elementAt(columnIndex);
return colName;
}
/**
* contenu d'une cellule
*/
public Object getValueAt(int rowIndex, int columnIndex) {
return (String) element[rowIndex][columnIndex];
}
/**
* changement du contenu d'une cellule
*/
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
element[rowIndex][columnIndex]=aValue.toString();
}
} |
Partager