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
| public class MyDefaultCellEditor extends DefaultCellEditor implements FocusListener {
// actionHandler = new CellEditorActionHandler();
public MyDefaultCellEditor(JTextField textField) {
super(textField);
setClickCountToStart(0);
editorComponent = textField;
editorComponent.setBorder(null);
editorComponent.addFocusListener(this);
}
public void focusGained(FocusEvent e) {
ligne = table.getSelectedRow();
colo = table.getSelectedColumn();
}
public void focusLost(FocusEvent e) {
pane= new JOptionPane();
String temp = table.getValueAt(ligne, colo).toString();
int etat = 0;
String quantite, Prix;
if(table.getSelectedColumn()==0){
if (temp.length() != 0) {
int temp2 = Integer.parseInt(temp);
for (int i = 0; i < liste.size(); i++) {
if (temp2 == liste.get(i)) {
pane.showMessageDialog(null, "Cet article a déjà été saisi","Avertissement",pane.WARNING_MESSAGE);
table.setValueAt("", ligne, 0);
etat = 1;
}
}
if (etat == 0) {
liste.add(temp2);
for (int i = 0; i < arts.getArticle().size(); i++) {
if (temp2 == arts.getArticle().get(i).getNumArt()&& arts.getArticle().get(i).getQuantiteArt()!=0) {
table.setValueAt(1, ligne, colo+1);
quantite= table.getValueAt(ligne, colo+1).toString();
table.setValueAt(arts.getArticle().get(i)
.getDescriptifArt(), ligne, colo + 2);
table.setValueAt(String.valueOf(arts.getArticle()
.get(i).getPrixCliArt()), ligne, colo + 3);
Prix=table.getValueAt(ligne, colo+3).toString();
/*prixTT = prixTT
+ (int) arts.getArticle().get(i).getPrixCliArt();
*/
prixHT=Float.parseFloat(quantite)*Float.parseFloat(Prix) ;
prixTT= prixTT + prixHT;
table.setValueAt(String.valueOf(prixHT), ligne, colo + 4);
jlbTotalBord.setText((String.valueOf(prixTT)));
prixTTC=(float) (prixTT+(prixTT*0.195));
System.out.println("le prix est "+prixTTC);
jlbTotalTtcR.setText((String.valueOf(prixTTC)));
//table.removeEditor();
}
}
if (table.getValueAt(ligne, 2).toString().length()!=0){
tm.addRow("");
}
else{
pane.showMessageDialog(null, "Cet article n'existe pas!",
"Avertissement",pane.WARNING_MESSAGE);
table.setValueAt("", ligne, 0);
}
}
}
}
}
} |
Partager