Beef Button, Vegan Button and the others all have the prices beside them when opened. The others at the bottom (Mustard Ketchup and the other condiment also have the numbers) I just need to know how to add numbers to int TotalArgent out of all the 3 checkboxes and 3 JRadioButtons
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Shopping
{
public static void main(String[] args) {
JFrame frame = new JFrame("Lister v1.0");
int TotalArgent = 0;
int BeefArgent = 15;
int PouletArgent = 20;
int VeganArgent = 70;
int KetchupArgent = 1;
int MoutardArgent = 2;
int CorcnichonsArgent = 17;
JPanel entreePanel = new JPanel();
final ButtonGroup entreeGroup = new ButtonGroup();
JRadioButton radioButtonBeef;
JRadioButton radioButtonVegan;
JRadioButton radioButtonPoulet;
entreePanel.add(radioButtonBeef = new JRadioButton("Boeuf 15$"));
radioButtonBeef.setActionCommand("Boeuf");
entreeGroup.add(radioButtonBeef);
entreePanel.add(radioButtonPoulet = new JRadioButton("Poulet 20$"));
radioButtonPoulet.setActionCommand("Poulet");
entreeGroup.add(radioButtonPoulet);
entreePanel.add(radioButtonVegan = new JRadioButton("Végétarien 70$", true));
radioButtonVegan.setActionCommand("Végétarien");
entreeGroup.add(radioButtonVegan);
final JPanel condimentsPanel = new JPanel();
condimentsPanel.add(new JCheckBox("Ketchup (1$)"));
condimentsPanel.add(new JCheckBox("Moutard (2$)"));
condimentsPanel.add(new JCheckBox("Cornichons (17$)"));
JPanel orderPanel = new JPanel();
JButton orderButton = new JButton("Place la commande, recoivre votre totale");
orderPanel.add(orderButton);
Container content = frame.getContentPane(); // unnecessary in 5.0+
content.setLayout(new GridLayout(3, 1));
content.add(entreePanel);
content.add(condimentsPanel);
content.add(orderPanel);
orderButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String entree =
entreeGroup.getSelection().getActionCommand();
System.out.println( "total: " + TotalArgent + "$\n" + entree + " sandwich");
Component[] components = condimentsPanel.getComponents();
for ( Component c : components ) {
JCheckBox cb = (JCheckBox)c;
if (cb.isSelected())
System.out.println("With " + cb.getText());
}
}
});
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setSize(400, 200);
frame.setVisible(true);
}
}