// penser à mettre l'opportunité de choisir plusieurs fois le meme element package com.creperiee.test; import java.awt.Button; import java.awt.Checkbox; import java.awt.Color; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.Label; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.math.BigInteger; import java.util.Enumeration; import java.util.Hashtable; import javax.swing.JOptionPane; import javax.swing.*; import java.awt.Choice; import java.util.Properties; import java.io.*; public class Cartee extends Frame { Properties props = new Properties(); FileInputStream in = new FileInputStream ("carte.txt"); GridLayout grid = new GridLayout (5,0); //(ligne,colonne) Label entree = new Label("entree"); Checkbox salade = new Checkbox(props.getProperty("libelle")); Choice maCombo = new Choice(); Checkbox melon = new Checkbox("melon"); Label cs = new Label("crepe salee"); Checkbox jf = new Checkbox("jambon fromage"); Checkbox complete = new Checkbox("complete"); Label csu = new Label("crepe sucree"); Checkbox su = new Checkbox("crepe au sucre"); Checkbox choc = new Checkbox("crepe au chocolat"); Label boi = new Label("boisson"); Checkbox coca = new Checkbox("coca cola"); Checkbox cidre = new Checkbox("cidre"); Button bout = new Button("ticket"); Button quitter = new Button("quitter l'application"); Hashtable associationProduitsPrix; public Cartee() { super("creperie"); initFrame(); addBouton(); initPrix(); initBoutonsListeners(); props.load (in); } private void initFrame() { setSize(250, 250); setLayout(new FlowLayout()); //sinon n'affiche qu'un seul element ds la fenetre setVisible(true); setBackground(Color.yellow); setForeground(Color.black); } private void addBouton() { add(entree); add(salade); add(maCombo); maCombo.add("1"); maCombo.add("2"); add(melon); add(cs); add(jf); add(complete); add(csu); add(su); add(choc); add(boi); add(coca); add(cidre); add(bout); add(quitter); } private void initPrix() { associationProduitsPrix = new Hashtable(); associationProduitsPrix.put(salade, new BigInteger("10")); associationProduitsPrix.put(melon, new BigInteger("5")); } private void initBoutonsListeners() { quitter.addActionListener(new ListenerQuitter()); bout.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { BigInteger total = new BigInteger("0"); Enumeration enu = associationProduitsPrix.keys(); while (enu.hasMoreElements()) { Checkbox check = (Checkbox) enu.nextElement(); if (check.getState()) { BigInteger prix = (BigInteger) associationProduitsPrix. get(check); total = total.add(prix); } } JOptionPane.showMessageDialog(null, "Total : " + total + " \u20ac"); } }); class ListenerQuitter implements ActionListener { public void actionPerformed(ActionEvent e) { System.exit(0); } } } public static void main(String[] args) ==> ERREUR LE VOID EST SOULIGNE EN ROUGE { Frame f = new Cartee(); }; }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question// penser à mettre l'opportunité de choisir plusieurs fois le meme element package com.creperiee.test; import java.awt.Button; import java.awt.Checkbox; import java.awt.Color; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.Label; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.math.BigInteger; import java.util.Enumeration; import java.util.Hashtable; import javax.swing.JOptionPane; import javax.swing.*; import java.awt.Choice; import java.util.Properties; import java.io.*; import java.awt.*; public class Cartee extends Frame { Properties props = new Properties(); FileInputStream in = new FileInputStream ("carte.txt"); GridLayout grid = new GridLayout (5,0); //(ligne,colonne) Label entree = new Label("entree"); Checkbox salade = new Checkbox(props.getProperty("libelle")); Choice maCombo = new Choice(); Checkbox melon = new Checkbox("melon"); Label cs = new Label("crepe salee"); Checkbox jf = new Checkbox("jambon fromage"); Checkbox complete = new Checkbox("complete"); Label csu = new Label("crepe sucree"); Checkbox su = new Checkbox("crepe au sucre"); Checkbox choc = new Checkbox("crepe au chocolat"); Label boi = new Label("boisson"); Checkbox coca = new Checkbox("coca cola"); Checkbox cidre = new Checkbox("cidre"); Button bout = new Button("ticket"); Button quitter = new Button("quitter l'application"); Hashtable associationProduitsPrix; public Cartee() { super("creperie"); initFrame(); addBouton(); initPrix(); initBoutonsListeners(); props.load (in); } private void initFrame() { setSize(250, 250); setLayout(new FlowLayout()); //sinon n'affiche qu'un seul element ds la fenetre setVisible(true); setBackground(Color.yellow); setForeground(Color.black); } private void addBouton() { add(entree); add(salade); add(maCombo); maCombo.add("1"); maCombo.add("2"); add(melon); add(cs); add(jf); add(complete); add(csu); add(su); add(choc); add(boi); add(coca); add(cidre); add(bout); add(quitter); } private void initPrix() { associationProduitsPrix = new Hashtable(); associationProduitsPrix.put(salade, new BigInteger("10")); associationProduitsPrix.put(melon, new BigInteger("5")); } private void initBoutonsListeners() { quitter.addActionListener(new ListenerQuitter()); bout.addActionListener(new ActionListener()); } public void actionPerformed(ActionEvent e) { BigInteger total = new BigInteger("0"); Enumeration enu = associationProduitsPrix.keys(); while (enu.hasMoreElements()) { Checkbox check = (Checkbox) enu.nextElement(); if (check.getState()) { BigInteger prix = (BigInteger) associationProduitsPrix. get(check); total = total.add(prix); } } JOptionPane.showMessageDialog(null, "Total : " + total + " \u20ac"); } } class ListenerQuitter implements ActionListener { public void actionPerformed(ActionEvent e) { System.exit(0); } } public static void main(String[] args) { Frame f = new Cartee(); }
// penser à mettre l'opportunité de choisir plusieurs fois le meme element package com.creperiee.test; import java.awt.Button; import java.awt.Checkbox; import java.awt.Color; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.Label; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.math.BigInteger; import java.util.Enumeration; import java.util.Hashtable; import javax.swing.JOptionPane; import javax.swing.*; import java.awt.Choice; import java.util.Properties; import java.io.*; import java.awt.*; public class Cartee extends Frame { // Properties props = new Properties(); // FileInputStream in = new FileInputStream ("carte.txt"); File propertiesFile = new File("carte.txt"); FileInputStream propertiesStream = new FileInputStream(propertiesFile); Properties props = new Properties() ; GridLayout grid = new GridLayout (5,0); //(ligne,colonne) Label entree = new Label("entree"); Checkbox salade = new Checkbox(props.getProperty("libelle")); Choice maCombo = new Choice(); Checkbox melon = new Checkbox("melon"); Label cs = new Label("crepe salee"); Checkbox jf = new Checkbox("jambon fromage"); Checkbox complete = new Checkbox("complete"); Label csu = new Label("crepe sucree"); Checkbox su = new Checkbox("crepe au sucre"); Checkbox choc = new Checkbox("crepe au chocolat"); Label boi = new Label("boisson"); Checkbox coca = new Checkbox("coca cola"); Checkbox cidre = new Checkbox("cidre"); Button bout = new Button("ticket"); Button quitter = new Button("quitter l'application"); Hashtable associationProduitsPrix; public Cartee() { super("creperie"); initFrame(); addBouton(); initPrix(); initBoutonsListeners(); props.load(propertiesStream); propertiesStream.close(); } private void initFrame() { setSize(250, 250); setLayout(new FlowLayout()); //sinon n'affiche qu'un seul element ds la fenetre setVisible(true); setBackground(Color.yellow); setForeground(Color.black); } private void addBouton() { add(entree); add(salade); add(maCombo); maCombo.add("1"); maCombo.add("2"); add(melon); add(cs); add(jf); add(complete); add(csu); add(su); add(choc); add(boi); add(coca); add(cidre); add(bout); add(quitter); } private void initPrix() { associationProduitsPrix = new Hashtable(); associationProduitsPrix.put(salade, new BigInteger("10")); associationProduitsPrix.put(melon, new BigInteger("5")); } private void initBoutonsListeners() { quitter.addActionListener(new ListenerQuitter()); bout.addActionListener(new ActionListener()); } public void actionPerformed(ActionEvent e) { BigInteger total = new BigInteger("0"); Enumeration enu = associationProduitsPrix.keys(); while (enu.hasMoreElements()) { Checkbox check = (Checkbox) enu.nextElement(); if (check.getState()) { BigInteger prix = (BigInteger) associationProduitsPrix. get(check); total = total.add(prix); } } JOptionPane.showMessageDialog(null, "Total : " + total + " \u20ac"); } } class ListenerQuitter implements ActionListener { public void actionPerformed(ActionEvent e) { System.exit(0); } } public static void main(String[] args) ==> ERREUR LE VOID EST SOULIGNE { Frame f = new Cartee(); }