-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableau.java
More file actions
90 lines (64 loc) · 1.94 KB
/
Tableau.java
File metadata and controls
90 lines (64 loc) · 1.94 KB
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
86
87
88
89
package formulaireProject;
import java.io.Serializable;
import javax.swing.JButton;
import javax.swing.table.AbstractTableModel;
public class Tableau extends AbstractTableModel implements Serializable{
Object[][]datas;
String[] title;
public Tableau(Object[][] datas, String[] title){
this.datas = datas;
this.title = title;
}
public int getColumnCount() {
return this.title.length;
}
public int getRowCount() {
return this.datas.length;
}
public Object getValueAt(int row, int col) {
return this.datas[row][col];
}
public String getColumnName(int x) {
return this.title[x];
}
public void setValueAt(Object value, int row, int col) {
if(!this.getColumnName(col).equals("suppression"))
this.datas[row][col] = value;
}
public Class getColumnClass(int col) {
return this.datas[0][col].getClass();
}
public boolean isCellEditable(int row, int col) {
if(this.getValueAt(0, col) instanceof JButton)
return false;
return true;
}
//ajouter une nouvelle ligne de donnee
public void addRow(Object[] donnee) {
int oldRowCount = this.getRowCount();
int oldColCount = this.getColumnCount();
int index = 0;
Object[][] temp = this.datas;
this.datas = new Object[oldRowCount+1][oldColCount];
for(Object[] value : temp)
this.datas[index++] = value;
this.datas[index] = donnee;
temp = null;
this.fireTableDataChanged();
}
//supprimer une ligne de donnee
public void deleteRow(int position) {
int indexVerifiant = 0 ; int indexAjoutant = 0;
int oldRowCount = this.getRowCount()-1;
int oldColCount = this.getColumnCount();
Object[][] temp = new Object[oldRowCount][oldColCount];
for(Object[] value : this.datas) {
if(indexVerifiant != position)
temp[indexAjoutant++] = value;
indexVerifiant++;
}
this.datas = temp;
temp = null;
this.fireTableDataChanged();
}
} //end of class