je veux récupérer les donnée qui sont sur un fichier .txt
la forme de mon fichier est la suivante:
2674.2
une seule ligne qui contient de poids
je veux récupérer les donnée qui sont sur un fichier .txt
la forme de mon fichier est la suivante:
2674.2
une seule ligne qui contient de poids
Quelle est la question?
Bonjour,
la question comment je peux récupérer cette valeur et la mettre dans mon programme java .
je veuxla mettre de le TextField poids
Merci
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292 import java.awt.*; import java.io.*; import java.util.*; import java.awt.event.*; import javax.swing.*; import java.util.Date; import java.text.SimpleDateFormat; import java.util.Locale; import java.sql.*; import java.sql.Statement; import java.sql.ResultSet; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; class FenText extends JFrame implements ActionListener { private double prixT; private JButton tomate,carotte,chouxfleur,brocoli,courgette,haricot,poivron,pommedeterre,oignon,ail,poire,pomme,orange,citron,annanas,raisin,banane,kiwi,peche,fraise,balance,annuler; private JPanel pan; private JTextField poids ; private JTextField prix ; private JTextField prixkg ; public FenText() { setSize(820, 720);//Définit sa taille : 680 pixels de large et 680 pixels de haut setTitle("Legumes & Freuits BIO chez Abderraouf CHEBBAH ");//Définit un titre pour notre fenêtre setResizable(false);//pour la résolution de la fenetre ne sera pas modifiable setLocationRelativeTo(null);//Pour mettre la fenetre au mileu d'ecran setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);////Termine le processus lorsqu'on clique sur la croix rouge pan = new JPanel();//creer un nouvelle panel prixkg = new JTextField(); prixkg.setEditable(false); prixkg.setPreferredSize(new Dimension(180,50)); pan.add(new JLabel ("PRIX KG ()")); pan.add(prixkg); poids = new JTextField(); poids.setEditable(false); poids.setPreferredSize(new Dimension(180,50)); pan.add(new JLabel("POIDS (g)")); pan.add(poids); prix = new JTextField(); prix.setEditable(false); prix.setPreferredSize(new Dimension(180,50)); pan.add(new JLabel ("PRIX ()")); pan.add(prix); /************************ajouter des photo pour les bouttons *****************************/ ImageIcon AnanasImage = new ImageIcon("ananas.png"); ImageIcon CitronImage = new ImageIcon("citron.png"); ImageIcon PommeImage = new ImageIcon("pomme.png"); ImageIcon BananeImage = new ImageIcon("banane.png"); ImageIcon RaisinImage = new ImageIcon("raisin.png"); ImageIcon KiwiImage = new ImageIcon("kiwi.png"); ImageIcon PoireImage = new ImageIcon("poire.png"); ImageIcon FraiseImage = new ImageIcon("fraise.png"); ImageIcon PecheImage = new ImageIcon("peche.png"); ImageIcon OrangeImage = new ImageIcon("orange1.png"); ImageIcon CourgetteImage = new ImageIcon("cougette.png"); ImageIcon AilImage = new ImageIcon("ail.png"); ImageIcon oignonImage = new ImageIcon("oignon.png"); ImageIcon HaricotImage = new ImageIcon("haricot.png"); ImageIcon BrocoliImage = new ImageIcon("brocoli.png"); ImageIcon PmmedeterreImage = new ImageIcon("pommedeterre.png"); ImageIcon TomateImage = new ImageIcon("tomate.png"); ImageIcon PoivrontImage = new ImageIcon("poivron.png"); ImageIcon CarotteiImage = new ImageIcon("carotte.png"); ImageIcon ChouxfleurImage = new ImageIcon("chouxfleur.png"); ImageIcon BlanceImage = new ImageIcon("balance.png"); ImageIcon AnnulerImage = new ImageIcon("annuler.png"); /**************Création des nouveux bouttons et metttre les imange dedans*****************/ carotte =new JButton("<html>CAROTTE BIO <br><br><br><br><br>1.50/Kg</html>",CarotteiImage); tomate =new JButton("<html>TOMATE BIO <br><br><br><br><br>1.50/Kg</html>",TomateImage); pommedeterre =new JButton("<html><br>POMME DE TERRE BIO <br><br><br>1.50/Kg</html>",PmmedeterreImage); poivron =new JButton("<html>POIVRON BIO <br><br><br><br><br>1.60/Kg</html>",PoivrontImage); courgette =new JButton("<html>COURGETTE BIO <br><br><br><br>1.10/Kg</html>",CourgetteImage); oignon =new JButton("<html>OIGNON BIO <br><br><br><br><br>1.50/Kg</html>",oignonImage); ail =new JButton("<html>AIL BIO <br><br><br><br><br>1.50/Kg</html>",AilImage); brocoli =new JButton("<html>BROCOLI BIO <br><br><br><br><br>1.80/Kg</html>",BrocoliImage); haricot =new JButton("<html>HARICOT BIO <br><br><br><br><br>1.40/Kg</html>",HaricotImage); chouxfleur =new JButton("<html>CHOUXFLEUR BIO <br><br><br><br>2.20/Kg</html>",ChouxfleurImage); kiwi =new JButton("<html>KIWI BIO <br><br><br><br>4.30/Kg</html>",KiwiImage); poire =new JButton("<html>POIRE BIO <br><br><br><br><br>1.50/Kg</html>",PoireImage); citron =new JButton("<html>CITRON BIO <br><br><br><br><br>1.50/Kg</html>",CitronImage); banane =new JButton("<html>BANANE BIO <br><br><br><br>1.99/Kg</html>",BananeImage); fraise =new JButton("<html>FRAISE BIO <br><br><br><br>2.90/Kg</html>",FraiseImage); peche =new JButton("<html>PECHE BIO <br><br><br><br>2.70/Kg</html>",PecheImage); annanas =new JButton("<html>ANNANAS BIO <br><br><br><br><br>1.50/Kg</html>",AnanasImage); raisin =new JButton("<html>RAISIN BIO <br><br><br><br><br>1.50/Kg</html>",RaisinImage); orange =new JButton("<html>ORANGE BIO <br><br><br><br>2.50/Kg</html>",OrangeImage); pomme =new JButton("<html>POMME BIO <br><br><br><br>3.00/Kg</html>",PommeImage); annuler =new JButton("<html>Annuler</html>",AnnulerImage); balance =new JButton("<html> Payer </html>",BlanceImage); pomme.addActionListener(this); /************************mettre les dimension des buttons *****************************/ carotte.setPreferredSize(new Dimension(185, 110)); //mettre le dimention du button poivron.setPreferredSize(new Dimension(185, 110)); courgette.setPreferredSize(new Dimension(185, 110)); brocoli.setPreferredSize(new Dimension(185, 110)); haricot.setPreferredSize(new Dimension(185, 110)); pommedeterre.setPreferredSize(new Dimension(185, 110)); oignon.setPreferredSize(new Dimension(185, 110)); ail.setPreferredSize(new Dimension(185, 110)); tomate.setPreferredSize(new Dimension(185, 110)); chouxfleur.setPreferredSize(new Dimension(185, 110)); kiwi.setPreferredSize(new Dimension(185, 110)); banane.setPreferredSize(new Dimension(185, 110)); fraise.setPreferredSize(new Dimension(185, 110)); peche.setPreferredSize(new Dimension(185, 110)); poire.setPreferredSize(new Dimension(185, 110)); raisin.setPreferredSize(new Dimension(185, 110)); annanas.setPreferredSize(new Dimension(185, 110)); citron.setPreferredSize(new Dimension(185, 110)); orange.setPreferredSize(new Dimension(185, 110)); pomme.setPreferredSize(new Dimension(185, 110)); /************************Ajouter les buttons dans le panel*****************************/ pan.add(haricot); pan.add(pommedeterre); pan.add(oignon); pan.add(ail); pan.add(tomate); pan.add(courgette); pan.add(poivron); pan.add(chouxfleur); pan.add(brocoli); pan.add(carotte); pan.add(banane); pan.add(poire); pan.add(annanas); pan.add(citron); pan.add(raisin); pan.add(fraise); pan.add(orange); pan.add(peche); pan.add(pomme); pan.add(kiwi); pan.add(balance); pan.add(annuler); setContentPane(pan); /************************ activer la fonction des buttons *****************************/ haricot.addActionListener(this); annuler.addActionListener(this); pommedeterre.addActionListener(this); oignon.addActionListener(this); ail.addActionListener(this); tomate.addActionListener(this); courgette.addActionListener(this); poivron.addActionListener(this); chouxfleur.addActionListener(this); brocoli.addActionListener(this); carotte.addActionListener(this); banane.addActionListener(this); poire.addActionListener(this); annanas.addActionListener(this); citron.addActionListener(this); raisin.addActionListener(this); fraise.addActionListener(this); orange.addActionListener(this); peche.addActionListener(this); pomme.addActionListener(this); kiwi.addActionListener(this); balance.addActionListener(this); } public void clear() { prixkg.setText(" "); prix.setText(" "); poids.setText(" "); } public void actionPerformed (ActionEvent e) //throws IOException pas possible { if (e.getSource() == haricot) //donner une action a ce button { prixkg.setText("1.40"); } if (e.getSource() == annuler) { clear(); } if (e.getSource() == pommedeterre) { prixkg.setText("1.50"); } if (e.getSource() == oignon) { prixkg.setText("1.50"); } if (e.getSource() == ail) { prixkg.setText("1.50"); } if (e.getSource() == tomate) { prixkg.setText("1.50"); } if (e.getSource() == courgette) { prixkg.setText("1.10"); } if (e.getSource() == poivron) { prixkg.setText("1.60"); } if (e.getSource() == chouxfleur) { prixkg.setText("2.20"); } if (e.getSource() == brocoli) { prixkg.setText("1.80"); } if (e.getSource() == carotte) { prixkg.setText("1.50"); } if (e.getSource() == banane) { prixkg.setText("1.99"); } if (e.getSource() == poire) { prixkg.setText("1.50"); } if (e.getSource() == annanas) { prixkg.setText("1.50"); } if (e.getSource() == citron) { prixkg.setText("1.50"); } if (e.getSource() == raisin) { prixkg.setText("1.50"); } if (e.getSource() == fraise) { prixkg.setText("2.90"); } if (e.getSource() == orange) { prixkg.setText("2.50"); } if (e.getSource() == peche) { prixkg.setText("2.70"); } if (e.getSource() == pomme) { prixkg.setText("3.00"); } if (e.getSource() == kiwi) { prixkg.setText("4.30"); } } } public class FenetreLegum3 { public static void main (String args[]) { FenText fen = new FenText(); fen.setVisible(true); } }
Tu dois commencer par lire le fichier ligne par ligne, puis pour chaque ligne, rechercher si la valeur que tu cherches s'y trouve.
enfait y a qu'une seule ligne et j'arrive par a la lire
Bonjour,
Fais un tour sur la FAQ qui te donnera ce qu'il faut pour y arriver : https://java.developpez.com/faq/java...igne-par-ligne
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager