Ce forum est maintenant fermé, seule cette archive statique reste consultable.
  FORUM Rue-Montgallet.com
  Programmation
  Java

  pb fichier JAVA

Bas de page
Auteur Sujet :

pb fichier JAVA

n°14512
crapaud
Profil : Jeune recrue
Posté le 06-08-2005 à 19:56:56  
 

bonjour !
voilà je rencontre un probleme pour lire un fichier texte dont je veux mettre les informations dans une frame
en effet je voudrais afficher un libellé (exple crepe au sucre) de type checkbox
(Checkbox salade = new Checkbox(props.getProperty("libelle" ));  ))  
 
mais ca ne m'affiche rien...
voici mon code :  

Code :
  1. package com.creperiee.test;
  2. import java.awt.Button;
  3. import java.awt.Checkbox;
  4. import java.awt.Color;
  5. import java.awt.FlowLayout;
  6. import java.awt.Frame;
  7. import java.awt.Label;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10. import java.math.BigInteger;
  11. import java.util.Enumeration;
  12. import java.util.Hashtable;
  13. import javax.swing.JOptionPane;
  14. import javax.swing.*;
  15. import java.awt.Choice;
  16. import java.util.Properties;
  17. import java.io.*;
  18. import java.awt.*;
  19. public class Cartee extends Frame
  20. {
  21.     File propertiesFile;
  22.     Properties props = new Properties() ;
  23.     FileInputStream propertiesStream;
  24.     Hashtable associationProduitsPrix;
  25.     GridLayout grid = new GridLayout(5, 0); //(ligne,colonne)  
  26.     Label entree = new Label("entree" );
  27.     Checkbox salade = new Checkbox(props.getProperty("libelle" )); ==> PB
  28.     Label lab = new Label(props.getProperty("prix" ));
  29.     Choice maCombo = new Choice();
  30.     Checkbox melon = new Checkbox(props.getProperty("libelle" ));
  31.     Label cs = new Label("crepe salee" );
  32.     Checkbox jf = new Checkbox("jambon fromage" );
  33.     Checkbox complete = new Checkbox("complete" );
  34.     Label csu = new Label("crepe sucree" );
  35.     Checkbox su = new Checkbox("crepe au sucre" );
  36.     Checkbox choc = new Checkbox("crepe au chocolat" );
  37.     Label boi = new Label("boisson" );
  38.     Checkbox coca = new Checkbox("coca cola" );
  39.     Checkbox cidre = new Checkbox("cidre" );
  40.     Button bout = new Button("ticket" );
  41.     Button quitter = new Button("quitter l'application" );
  42.     public Cartee()
  43.     {
  44.         super("creperie" );
  45.         initFrame();
  46.         addBouton();
  47.         // initPrix();  
  48.         // initBoutonsListeners();  
  49.           Properties props = new Properties();
  50.         File propertiesFile = new File("carte.txt" );
  51.         try {
  52.             FileInputStream propertiesStream = new FileInputStream(
  53.                     propertiesFile);
  54.         }
  55.         catch (FileNotFoundException e)
  56.         {
  57.             System.err.println("Fichier non trouvé" );
  58.         } catch (IOException e)
  59.         {
  60.             System.err.println("Impossible de lire" );
  61.         }
  62.         //props.load(propertiesStream);  
  63.         // propertiesStream.close();  
  64.         quitter.addActionListener(new ListenerQuitter());
  65.         //  bout.addActionListener(new ActionListener());  
  66.     }
  67.     private void initFrame()
  68.     {
  69.         setSize(250, 250);
  70.         setLayout(new FlowLayout()); //sinon n'affiche qu'un seul element ds la fenetre  
  71.         setVisible(true);
  72.         setBackground(Color.yellow);
  73.         setForeground(Color.black);
  74.     }
  75.     private void addBouton()
  76.     {
  77.         add(entree);
  78.         add(salade);
  79.         add(lab);
  80.         add(maCombo);
  81.         maCombo.add("1" );
  82.         maCombo.add("2" );
  83.         add(melon);
  84.         add(cs);
  85.         add(jf);
  86.         add(complete);
  87.         add(csu);
  88.         add(su);
  89.         add(choc);
  90.         add(boi);
  91.         add(coca);
  92.         add(cidre);
  93.         add(bout);
  94.         add(quitter);
  95.     }
  96.     //private void initPrix()  
  97.     //{  
  98.     //    associationProduitsPrix = new Hashtable();  
  99.     //   associationProduitsPrix.put(salade, new BigInteger("10" ));  
  100.     //   associationProduitsPrix.put(melon, new BigInteger("5" ));  
  101.     // }  
  102.     private void initBoutonsListeners()
  103.     {
  104.         quitter.addActionListener(new ListenerQuitter());
  105.     }
  106.     public void ActionPerformed(ActionEvent e)
  107.     {
  108.         BigInteger total = new BigInteger("0" );
  109.         Enumeration enu = associationProduitsPrix.keys();
  110.         while (enu.hasMoreElements())
  111.         {
  112.             Checkbox check = (Checkbox) enu.nextElement();
  113.             if (check.getState())
  114.             {
  115.                 BigInteger prix = (BigInteger)
  116.                                   associationProduitsPrix.get(
  117.                                           check);
  118.                 total = total.add(prix);
  119.             }
  120.             JOptionPane.showMessageDialog(null,
  121.                                           "Total : " + total +
  122.                                           " \u20ac" );
  123.         }
  124.     }
  125.     class ListenerQuitter implements ActionListener
  126.     {
  127.         public void actionPerformed(ActionEvent e)
  128.         {
  129.             System.exit(0);
  130.         }
  131.     }
  132.         public static void main(String[] args)
  133.         {
  134.             Frame f = new Cartee();
  135.         }
  136.     }


 
merci !!

mood
Pub
Posté le 06-08-2005 à 19:56:56  
 

  FORUM Rue-Montgallet.com
  Programmation
  Java

  pb fichier JAVA

© 2000-2024 Forum.rue-montgallet.com - Tous droits réservés