Bonjour,
je voudrai faire la sommes des montants se touvant dans une jtable; ma jtable à 3 colonnes;("designation;quantité;prix unitaire; montant"); le montant=quantité*prix unitaire pour chaque désignation; j'ai ajouter un bouton "calculer" qui affiche dans un jtextfield le total des montants;je ne sait pas comme le faire, je n'ai pas de cours ; voici mon programme :

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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
class Facture extends JFrame implements ActionListener{
	JButton b1,b2,b3,b4;
	JTextField t1,t2,t3,t4;
	JLabel l1,l2,l3,l4;
	JTable T;
	DefaultTableModel model;
	String col[]={"Designation","prix unitaire","quantité","montant"};
	String donnees[][]={{"lait","10","5","50"},{"the","20","5","100"}};
	JPanel p1,p2,p3,p4,p5;
	JScrollPane jsp;
	BorderLayout d3;
	JMenuBar jmb;	
  JMenu jm1,jm2;
  JMenuItem jmr,jmv,jml,jmh;
 
Facture(){
		setTitle("Facture");
	    p1=new JPanel();
		GridLayout d1=new GridLayout(3,2);
		p1.setLayout(d1);
    	t1=new JTextField(10);
	    t2=new JTextField(10);
	    t3=new JTextField(20);
     	t4=new JTextField(20);
	    l1=new JLabel("     Désignation");
	    l2=new JLabel("     prix unitaire");
	    l3=new JLabel("     quantité");
	    l4=new JLabel("Total");
        b1=new JButton("quiter");
        b2=new JButton("ajouter");
	    b3=new JButton("supprimer");
	    b4=new JButton("Calculer");
	    jmb=new JMenuBar();
	    setJMenuBar(jmb);
        jm1=new JMenu("couleurs");
        jm2=new JMenu("dimension");
	    jmb.add(jm1);
	    jmb.add(jm2);
        jmv=new JMenuItem("vert");
        jmr=new JMenuItem("rouge");
        jml=new JMenuItem("largeur");
        jmh=new JMenuItem("hauteur");
        p1.add(l1);
  	    p1.add(t1);
	    p1.add(l2);
	    p1.add(t2);
     	p1.add(l3);
    	p1.add(t3);
	    p2=new JPanel();
	GridLayout d2=new GridLayout(1,3);
	p2.setLayout(d2);
	    p2.add(b1);
	    p2.add(b2);
	    p2.add(b3);
 
	 model= new DefaultTableModel(donnees,col);
	 T=new JTable(model);
	 jsp = new JScrollPane(T); 
 	 p3=new JPanel();
	 d3 =new BorderLayout();
	 p3.setLayout(d3);
     p3.add(jsp);
 
    p5=new JPanel();
    GridLayout d5=new GridLayout(1,3);
    p5.setLayout(d5);
    p5.add(b4);
    p5.add(l4);
    p5.add(t4);
 
	p4=new JPanel();
	GridLayout d4 =new GridLayout(4,1,20,20);
	p4.setLayout(d4);
	p4.add(p1);
	p4.add(p2);
	p4.add(p3);
	p4.add(p5);
	setContentPane(p4);
	jm1.add(jmr);
	jm1.add(jmv);
	jm2.add(jml);
	jm2.add(jmh);
    jmr.addActionListener(this);
	jmv.addActionListener(this);
	jml.addActionListener(this);
	jmh.addActionListener(this);
   	b1.addActionListener(this);
	b2.addActionListener(this);
	b3.addActionListener(this);
	b4.addActionListener(this);
   }
	public void actionPerformed(ActionEvent ev){
		model= new DefaultTableModel(donnees,col);
		if(ev.getSource()==jmr){
	      p4.setBackground(Color.red);
 
			}
		if(ev.getSource()==jmv){
		p4.setBackground(Color.green);
				}				
		if(ev.getSource()==jml){
	        	int l;
		l=Integer.parseInt(JOptionPane.showInputDialog(null,"donner la largeur:"));
						}
 
        if(ev.getSource()==jmh){
	        	int h;
	        	h=Integer.parseInt(JOptionPane.showInputDialog(null,"donner la hauteur:"));
 
				}
			if(ev.getSource()==b1){
			System.exit(0);
 
			}
 
		if(ev.getSource()==b2){
		double a2,a3,M;
		String a1;
		    a1=(t1.getText());
		    do{
			a2=Double.parseDouble(t2.getText());
		}while(a2<=0);
		    a3=Double.parseDouble(t3.getText());
		    M=a2*a3;
		   	 model.insertRow(T.getRowCount() ,new Object[]{a1,""+a2,""+a3,""+M});
	    	T.setModel(model); 
	    }
 
		if(ev.getSource()==b3){
			int k;
			k=Integer.parseInt(JOptionPane.showInputDialog(null,"quelle ligne voulez vous supprimer:"));
			model.removeRow(k);
			T.setModel(model);
		}
			if(ev.getSource()==b4){?
				(aider moi à ce niveau)	}
  }			
 }	
 
class TestFacture{
	public static void main(String Arg[]){
		try{
		Facture f=new Facture();
		f.setSize(500,300);
		f.show();
		}catch(Exception e){
		}
	}
}



<config>Windows XP / Internet Explorer 7.0</config>