Bonjour à tous.

Je travaille sur un panel de caisse qui avance petit à petit. Un scan de code barre provoque une recherche et l'affichage du produit cible, qui est ensuite ajouté à la JTable simulant le panier. J'en suis à l'étape de validation du panier : c'est à dire un bouton déclenche l'ouverture d'un Joptionpane reprenant le panier actuel, invitant l'utilisateur à imprimer une facture, revenir en arrière ou valider et donc envoyer le contenu du panier en base. Là ou je suis perdu c'est que je ne sais pas quelle méthode est la plus adaptée pour passer les données de la JTable du panier vers la JTable du formulaire, qui partagent le même modèle.

Bien cordialement

L'extrait de mon panel de caisse
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
		tableaupan.setTableHeader(null);
		tableaupan.getColumnModel().getColumn(0).setPreferredWidth(5);
		tableaupan.getColumnModel().getColumn(1).setPreferredWidth(5);
		tableaupan.getColumnModel().getColumn(2).setPreferredWidth(220);
		tableaupan.getColumnModel().getColumn(3).setPreferredWidth(40);
		JScrollPane scroll = new JScrollPane(tableaupan);
		scroll.getViewport().setBackground(Color.WHITE);
		pangauche.add(scroll, mpan); 
 
		jButton2 = new JButton("Supprimer");
		mpan.gridwidth = 1;
		mpan.gridx = 0;
		mpan.gridy = 2;
		pangauche.add(jButton2, mpan);
 
		jButton3 = new JButton("Valider l'achat");
		mpan.gridwidth = 1;
		mpan.gridx = 1;
		mpan.gridy = 2;
		pangauche.add(jButton3, mpan);
 
		jButton3.addActionListener(new ActionListener(){
	        public void actionPerformed(ActionEvent arg0) {
	        	Formvalidcaisse zd = new Formvalidcaisse(null, "Valider la transaction", true);
	        	Formvalidcaisseinfo zInfo = zd.showFormcom(); 
		        JOptionPane jop = new JOptionPane();
		        jop.showMessageDialog(null, zInfo.toString(), "Finaliser transaction", JOptionPane.INFORMATION_MESSAGE);
	        }
 
	      });
 
                       //---Bouton pour éliminer les lignes
			jButton2.addActionListener(new java.awt.event.ActionListener() {
			    @Override
			    public void actionPerformed(java.awt.event.ActionEvent evt) {
			    	    int[] selection = tableaupan.getSelectedRows();
			    	    for(int j = selection.length - 1; j >= 0; j--){
			    	   	modele.removeCaisse(selection[j]);
			    	 }
			    }
			    });	    
			//------------- --------------------------------------------------  
 
		    //---Bouton qui déclenche l'ajout du produit dans le panier----------
			jButton1.addActionListener(new java.awt.event.ActionListener() {
			    @Override
			    public void actionPerformed(java.awt.event.ActionEvent evt) {
			    	//---Si le JTextfield contenant le titre produit n'est pas vide alors l'ajoute est possible----------
			    	if(JTitre.getText().length()!=0)
			    	{	
			    	mont = (mont + prixtotal);
			    	JMontant.setText((df.format(mont))+" €");
			    	JTTicket.setText((df.format(mont)));
			    	System.out.println(df.format(mont));
			    	modele.addCaisse(new Caisse(idprod,cqte, JTitre.getText().toString(),prixtotal));
			    	}
			    	else
			    	{
			    		   JOptionPane.showMessageDialog(null, "Il n'y a rien à ajouer au panier !", "Erreur d'ajout au panier",
                                   JOptionPane.ERROR_MESSAGE);
			    	}
			    	//    int[] selection = tableaupan.getSelectedRows();
			    	 //   for(int j = selection.length - 1; j >= 0; j--){
			    	 //  	modele.removeCaisse(selection[j]);
			    	 //}
			    }
 
			    });	  
	 }
}
Le formulaire de validation
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
package com.pl.app;
 
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
 
public class Formvalidcaisse extends JDialog {
 
  private boolean sendData;
  private Formvalidcaisseinfo zInfo = new Formvalidcaisseinfo();
  private CaisseTableModel modele = new CaisseTableModel();
  private JButton JButton1,JButton2;
  private JTable tableaupan;
 
  public Formvalidcaisse(JFrame parent, String title, boolean modal){
    super(parent, title, modal);
    this.setSize(750, 500);
    this.setLocationRelativeTo(null);
    this.setResizable(false);
    this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    this.initComponent();
  }
 
  public Formvalidcaisseinfo showFormcom(){
    this.sendData = false;
    this.setVisible(true);      
    return this.zInfo;      
  }
 
 
  private void initComponent(){
	  this.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
 
		c.gridx = 0;
		c.gridy = 0;
		c.gridwidth = 3;
		tableaupan = new JTable(modele);
		tableaupan.setBackground(Color.white);
		tableaupan.setTableHeader(null);
		tableaupan.getColumnModel().getColumn(0).setPreferredWidth(5);
		tableaupan.getColumnModel().getColumn(1).setPreferredWidth(5);
		tableaupan.getColumnModel().getColumn(2).setPreferredWidth(220);
		tableaupan.getColumnModel().getColumn(3).setPreferredWidth(40);
		JScrollPane scroll = new JScrollPane(tableaupan);
		scroll.getViewport().setBackground(Color.WHITE);
		this.add(scroll, c); 
 
		JButton FactureButton = new JButton("Facture");
		c.gridx = 0;
		c.gridy = 1;
		c.gridwidth = 1;
		this.add(FactureButton, c);
 
		JButton okButton = new JButton("Valider la transaction");
		c.gridx = 2;
		c.gridy = 1;
		c.gridwidth = 1;
		this.add(okButton, c);
 
		okButton.addActionListener(new ActionListener(){
	        public void actionPerformed(ActionEvent arg0) {        
	          setVisible(false);
	        }
	      });
 
		JButton cancelButton = new JButton("Retour");
		c.gridx = 1;
		c.gridy = 1;
		c.gridwidth = 1;
		this.add(cancelButton, c);
 
		cancelButton.addActionListener(new ActionListener(){
	        public void actionPerformed(ActionEvent arg0) {
	          setVisible(false);
	        }   
	    });
  }
 
}
Ma classe de données du panier

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
package com.pl.app;
 
//Cette classe permet de préparer les objets qui vont recevoir les informations du panier
 
public class Caisse {
	private int idprodp = 0;
	private int quantp = 0;
    private String titrep;
    private float prixp = 0;
 
    public Caisse(int idprodp, int quantp,String titrep, float prixp) {
        super();
        this.idprodp = idprodp;
        this.quantp = quantp;
        this.titrep = titrep;
        this.prixp = prixp;
    }
 
    public int getidprodp() {
        return idprodp;
      }
 
    public void setidprodp(int idprodp) {
        this.idprodp = idprodp;
      }
 
    public int getquantp() {
        return quantp;
      }
 
    public void setquantp(int quantp) {
        this.quantp = quantp;
      }
 
    public String getTitrep() {
        return titrep;
    }
 
    public void setTitrep(String titrep) {
        this.titrep = titrep;
    }
 
    public float getprixp() {
        return prixp;
      }
 
    public void setprixp(float prixp) {
        this.prixp = prixp;
      }
 
}