how do you store numbers in the choices. ex. soda is $.75 and tax is $.07 then it equals a new total. I've been trying to use the Itemlistener but i can't figure out how to store the numbers
import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.ButtonGroup; import javax.swing.ComboBoxModel; import javax.swing.DefaultComboBoxModel; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JRadioButton; import javax.swing.JTextField;
import javax.swing.WindowConstants; import javax.swing.SwingUtilities;
public class BurgeMenu extends javax.swing.JFrame implements ItemListener
{
private JLabel jLabel1;
private JLabel jLabel2;
private JLabel jLabel3;
private JLabel jLabel4;
private JLabel jLabel5;
private JRadioButton jRadioButton5;
private JRadioButton jRadioButton4;
private JRadioButton jRadioButton3;
private JRadioButton jRadioButton2;
private JRadioButton jRadioButton1;
private ButtonGroup buttonGroup1;
private JTextField totalbox;
private JTextField taxbox;
private JTextField subtbox;
private JButton jButton1;
private JButton jButton2;
private JLabel jLabel8;
private JLabel jLabel7;
private JLabel jLabel6;
private JComboBox jComboBox2;
private JComboBox jComboBox1;
private JTextField sprqst;
double Cheeseburger = 2.49;
double DoubleCheeseburger = 3.89;
double TripleCheeseburger = 4.99;
double Medium = .75;
double Large = 1.25;
double tax = .07;
double subtotal;
double total;
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
BurgeMenu inst = new BurgeMenu();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
public BurgeMenu() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
{
jLabel1 = new JLabel();
getContentPane().add(jLabel1);
jLabel1.setText("McDowell's");
jLabel1.setBounds(204, 0, 125, 30);
}
{
jLabel2 = new JLabel();
getContentPane().add(jLabel2);
jLabel2.setText("ComboMeal");
jLabel2.setBounds(24, 43, 90, 16);
}
{
jLabel3 = new JLabel();
getContentPane().add(jLabel3);
jLabel3.setText("SpecialRequest:");
jLabel3.setBounds(24, 76, 129, 16);
}
{
jLabel4 = new JLabel();
getContentPane().add(jLabel4);
jLabel4.setText("Drinks:");
jLabel4.setBounds(24, 110, 72, 16);
}
{
sprqst = new JTextField();
getContentPane().add(sprqst);
sprqst.setBounds(171, 73, 158, 22);
}
{
ComboBoxModel jComboBox1Model =
new DefaultComboBoxModel(
new String[] { "1.Cheeseburger", "2.Double Cheeseburger","3.Triple Cheeseburger" });
jComboBox1 = new JComboBox();
getContentPane().add(jComboBox1);
jComboBox1.setModel(jComboBox1Model);
jComboBox1.setBounds(171, 36, 166, 22);
jComboBox1.addItemListener(this);
}
{
jLabel5 = new JLabel();
getContentPane().add(jLabel5);
jLabel5.setText("Size:");
jLabel5.setBounds(24, 163, 56, 16);
}
{
ComboBoxModel jComboBox2Model =
new DefaultComboBoxModel(
new String[] { "Small", "Medium","Large" });
jComboBox2 = new JComboBox();
getContentPane().add(jComboBox2);
jComboBox2.setModel(jComboBox2Model);
jComboBox2.setBounds(171, 160, 132, 22);
jComboBox2.addItemListener(this);
}
{
jLabel6 = new JLabel();
getContentPane().add(jLabel6);
jLabel6.setText("Subtotal:");
jLabel6.setBounds(24, 205, 72, 16);
}
{
jLabel7 = new JLabel();
getContentPane().add(jLabel7);
jLabel7.setText("Tax:");
jLabel7.setBounds(24, 245, 56, 16);
}
{
jLabel8 = new JLabel();
getContentPane().add(jLabel8);
jLabel8.setText("Total:");
jLabel8.setBounds(24, 288, 56, 16);
}
{
jButton1 = new JButton();
getContentPane().add(jButton1);
jButton1.setText("Submit Order");
jButton1.setBounds(171, 324, 117, 22);
}
{
jButton2 = new JButton();
getContentPane().add(jButton2);
jButton2.setText("Clear");
jButton2.setBounds(316, 324, 71, 22);
}
{
subtbox = new JTextField();
getContentPane().add(subtbox);
subtbox.setBounds(171, 202, 68, 22);
}
{
taxbox = new JTextField();
getContentPane().add(taxbox);
taxbox.setBounds(171, 242, 68, 22);
}
{
totalbox = new JTextField();
getContentPane().add(totalbox);
totalbox.setBounds(171, 285, 68, 22);
}
{
jRadioButton1 = new JRadioButton();
getContentPane().add(jRadioButton1);
jRadioButton1.setText("Coke");
jRadioButton1.setBounds(171, 108, 60, 20);
getButtonGroup1().add(jRadioButton1);
}
{
jRadioButton2 = new JRadioButton();
getContentPane().add(jRadioButton2);
jRadioButton2.setText("Sprite");
jRadioButton2.setBounds(171, 131, 64, 20);
getButtonGroup1().add(jRadioButton2);
}
{
jRadioButton3 = new JRadioButton();
getContentPane().add(jRadioButton3);
jRadioButton3.setText("Diet Coke");
jRadioButton3.setBounds(236, 108, 85, 20);
getButtonGroup1().add(jRadioButton3);
}
{
jRadioButton4 = new JRadioButton();
getContentPane().add(jRadioButton4);
jRadioButton4.setText("Root Beer");
jRadioButton4.setBounds(235, 131, 82, 20);
getButtonGroup1().add(jRadioButton4);
}
{
jRadioButton5 = new JRadioButton();
getContentPane().add(jRadioButton5);
jRadioButton5.setText("Orange");
jRadioButton5.setBounds(321, 108, 68, 20);
getButtonGroup1().add(jRadioButton5);
}
pack();
this.setSize(500, 402);
}
catch (Exception e)
{
//add your error handling code here
e.printStackTrace();
}
}
private ButtonGroup getButtonGroup1()
{
if(buttonGroup1 == null)
{
buttonGroup1 = new ButtonGroup();
}
return buttonGroup1;
}
public void itemStateChanged(ItemEvent event)
{
if( event.getStateChange( ) == ItemEvent.SELECTED)
subtbox.setText("");
else if( event.getStateChange( ) == 1)
subtbox.setText("Cold");
}
}