Bonsoir tout le monde
J'ai un peux avancé dans la relation entre le composants et methode.
Mai j'ai encore un petit souci.
Voici la class Element.
Voici la class monnayeur.
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178 import java.awt.*; import java.awt.event.*; import java.awt.Color.*; import java.awt.Font.*; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.*; public class Element extends Panel implements ActionListener { Button cafe; Button cafelait; Button chocolat; Button the; TextField animation; Button cinqcent; Button dixcent; Button vingtcent; Button cinquantcent; Button eurro; TextField txtrendmoncinqcent; TextField textrendmondixcent; TextField textrendmonvingtcent; TextField textrendmoncinquantcent; TextField textrendmonunerro; public Element () { Label titre = new Label("Machine à café"); this.add(titre); titre.setForeground(Color.blue); Font tritrefont = titre.getFont(); tritrefont = tritrefont.deriveFont(Font.BOLD).deriveFont(14f); titre.setFont(tritrefont); cafe = new Button("café"); cafe.addActionListener(this); this.add(cafe); cafelait = new Button("café au lait"); cafelait.addActionListener(this); this.add(cafelait); chocolat = new Button("chocolat"); chocolat.addActionListener(this); this.add(chocolat); the = new Button("the"); the.addActionListener(this); this.add(the); TextField animation = new TextField(20); this.add(animation); cinqcent = new Button("0,5 centimes"); cinqcent.addActionListener(this); this.add(cinqcent); dixcent = new Button("0,10 centimes"); dixcent.addActionListener(this); this.add(dixcent); vingtcent = new Button("0,20 centimes"); vingtcent.addActionListener(this); this.add(vingtcent); cinquantcent = new Button("0,50 centimes"); cinquantcent.addActionListener(this); this.add(cinquantcent); eurro = new Button("1"); eurro.addActionListener(this); this.add(eurro); Label rendmoncinqcent = new Label("Nombre de piece de 5 centimes à rendre"); this.add(rendmoncinqcent); txtrendmoncinqcent = new TextField(15); this.add(txtrendmoncinqcent); Label rendmondixcent = new Label("Nombre de piece de 10 centimes à rendre"); this.add(rendmondixcent); textrendmondixcent = new TextField(15); this.add(textrendmondixcent); Label rendmonvingtcent = new Label("Nombre de piece de 20 centimes à rendre"); this.add(rendmonvingtcent); textrendmonvingtcent = new TextField(15); this.add(textrendmonvingtcent); Label rendmoncinquantcent = new Label("Nombre de piece de 50 centimes à rendre"); this.add(rendmoncinquantcent); textrendmoncinquantcent = new TextField(15); this.add(textrendmoncinquantcent); Label rendmonunerro = new Label("Nombre de piece de 1 à rendre"); this.add(rendmonunerro); textrendmonunerro = new TextField(15); this.add(textrendmonunerro); } public void actionPerformed(ActionEvent evt) { Object source = evt.getSource(); Monnayeur mo = new Monnayeur(); Boolean cinq; Boolean dix; Boolean vingt; Boolean cinquante; Boolean uneurro; Boolean caf; Boolean cafelai; Boolean chocola; Boolean th; boolean valide; int sr=0,sar=0,cout=0, rend5c=0, rend10c=0, rend20c=0,rend50c=0, rend1e=0,rendmoncinquantcent=0, rendmonunerro=0, rendmonvingtcent=0,rendmondixcent=0,rendmoncinqcent=0, nb20c=0, nb50c=0, nb1=0, nb10c=0, nb5c=0; int []tab = new int[5]; valide=true; animation.setText(mo.piecedispo(valide, nb20c, nb50c, nb1, nb10c, nb5c)); if ((source==cinqcent) ||(source==dixcent)||(source==vingtcent)||(source==eurro)) { cinq=true; dix=true; vingt=true; cinquante=true; uneurro=true; animation.setText(mo.achatbistrot( cinq , dix , vingt , cinquante , uneurro, sr, sar, cout)); tab=mo.rendmonnaie( rendmoncinquantcent, rendmonunerro, rendmonvingtcent, rendmondixcent, rendmoncinqcent, nb20c, nb50c, nb1, nb10c, nb5c); rend5c=tab[5]; rend10c=tab[4]; rend20c=tab[3]; rend50c=tab[2]; rend1e=tab[1]; txtrendmoncinqcent.setText(String.valueOf(rend5c)); textrendmondixcent.setText(String.valueOf(rend10c)); textrendmonvingtcent.setText(String.valueOf(rend20c)); textrendmoncinquantcent.setText(String.valueOf(rend50c)); textrendmonunerro.setText(String.valueOf(rend1e)); } if(source==cafe || source==cafelait || source==chocolat || source==the) { caf=true; cafelai=true; th=true; chocola=true; animation.setText(mo.instruct( caf,chocola,th,cafelai,sr, sar, cout)); } } }
Escusé moi il y a au moin 320 lignes.
Il n'y a plus d'erreur de compilation, mai l'applet ne s'ouvre pas, c'est marqué en bas à droite javanullpointerexeption et apres echec au chargement java.
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210 import java.awt.*; import java.awt.event.*; public class Monnayeur { Sound son = new Sound(); int sr=0, sar=0, cout=0; String boisson=""; Boolean cinq=false; Boolean dix=false; Boolean vingt=false; Boolean cinquant=false; Boolean uneurro=false; Boolean cafe=false; Boolean cafelait=false; Boolean chocolat=false; Boolean the=false; boolean valide=false; String message="Prennez un momment de détente."; int nb5c=0, nb10c=0, nb20c=0, nb50c=0 , nb1e=0; int textrendmonunerro=0, textrendmoncinquantcent=0, textrendmonvingtcent=0, textrendmondixcent=0, txtrendmoncinqcent=0; public String achatbistrot(Boolean cinq ,Boolean dix ,Boolean vingt ,Boolean cinquant , Boolean uneurro,int sr, int sar, int cout) { message="Prenez un momment de détente."; String piece; if(cinq==true) { sr=sr+5; son.piece(); message="somme reçu" + sr; } else if(dix==true) { sr=sr+10; son.piece(); message="somme reçu" + sr; } else if(vingt==true) { sr=sr+20; son.piece(); message="somme reçu" + sr; } else if(cinquant==true) { sr=sr+50; son.piece(); message="somme reçu" + sr; } else if(uneurro==true) { sr=sr+100; son.piece(); message="somme reçu" + sr; } return message; } public String instruct(Boolean cafe, Boolean cafelait, Boolean chocolat, Boolean the,String message,int sar, int cout, int sr) { if((cafe==true && sr==0) ||(cafelait==true && sr==0)||(chocolat==true && sr==0)||(the==true && sr==0)) { message="Somme insuffisante"; } else { sar = sr-cout; sar = sar*10; son.cafe(); message="je vous rends la somme : de" + sar; } return message; } public String piecedispo(boolean valide, int nb5c, int nb10c, int nb20c, int nb50c,int nb1e) { int cinpc=0, dixc=0, vingtc=0, cinquc=0, uneurro=0; if(valide==true) { nb5c = 0 ; String texteDansCinpc = Integer.toString(cinpc); if ( texteDansCinpc != null && texteDansCinpc.length() > 0 ) { nb5c = Integer.parseInt( texteDansCinpc ); } nb10c = 0 ; String texteDansDixc = Integer.toString(dixc); if ( texteDansDixc != null && texteDansDixc.length() > 0 ) { nb10c = Integer.parseInt( texteDansDixc ); } nb20c = 0 ; String texteDansvingtc = Integer.toString(vingtc); if ( texteDansvingtc != null && texteDansvingtc.length() > 0 ) { nb20c = Integer.parseInt( texteDansvingtc ); } nb50c = 0 ; String texteDanscinquc = Integer.toString(cinquc); if ( texteDanscinquc != null && texteDanscinquc.length() > 0 ) { nb50c = Integer.parseInt( texteDanscinquc ); } nb1e = 0 ; String texteDansuneurro = Integer.toString(uneurro); if ( texteDansuneurro != null && texteDansuneurro.length() > 0 ) { nb1e = Integer.parseInt( texteDansuneurro ); } if(nb5c==0 && nb10c==0 && nb20c==0 && nb50c==0 && nb1e==0) { message="Je ne rend pas la monnaie."; } } return message; } public int [] rendmonnaie(int nb5c,int nb10c, int nb20c, int nb50c, int nb1, int textrendmonunerro, int textrendmoncinquantcent, int textrendmonvingtcent,int textrendmondixcent, int txtrendmoncinqcent) { int tab[] = new int[5]; do { if(sar<=200) { nb1e=nb1e-1; textrendmonunerro=textrendmonunerro+1; tab[1]=textrendmonunerro; } else if(sar>=50) { nb50c=nb50c-1; textrendmoncinquantcent=textrendmoncinquantcent+1; tab[2]=textrendmoncinquantcent; } else if(sar>=20) { nb20c=nb20c-1; textrendmonvingtcent=textrendmonvingtcent+1; tab[3]=textrendmonvingtcent; } else if(sar>=10) { nb10c=nb10c-1; textrendmondixcent=textrendmondixcent+1; tab[4]=textrendmondixcent; } else if(sar>=5) { nb5c=nb5c-1; txtrendmoncinqcent=txtrendmoncinqcent+1; tab[5]=txtrendmoncinqcent; } } while(sar==sr); return tab; } public void main (String [] args) { piecedispo(valide, nb5c, nb10c, nb20c, nb50c, nb1e); achatbistrot(cinq, dix, vingt, cinquant, uneurro, sr, sar, cout); instruct(cafe, cafelait, chocolat, the, message, sar, cout, sr); rendmonnaie(nb5c, nb10c, nb20c, nb50c, nb1e, textrendmonunerro, textrendmoncinquantcent, textrendmonvingtcent, textrendmondixcent, txtrendmoncinqcent); } }
Pourriez vous m'aider à régler ce petit probleme.
Merci.
Cordialement
A bientôt
Partager