Basically, I have a price quoter that I am working on. The way it should work is:
The user selects the quantity of cards from the combo box.
In the textfield a price displays once selected. (i.e. 100 = $8.95).
(I have this segment working already.)
Next the user selects whether they need both sides of the card printed on or not.
Updated price displays. (i.e. 100 + both sides = $11.95)
Next comes the delivery timeframe (i.e. 100 + both + two days = 38.95)
And finally whether they need us to design their card or not (100 + both + 2 days + yes = 53.95)
I've been working at this for awhile now, and have determined the best way to go about this is to have if statements add values to the initial value. (i.e. 100 = 8.95, both = +3, two = +27, yes = +15, total =53.95)
The sides and delivery values depends on the selected quantity.
Any and all help is greatly appreciated. Here is the code:
import javax.swing.*;
import java.awt.event.*;
public class BCard extends JFrame
{
private JPanel panel;
//I commented these out until I can fix the problems in the code//
//private JPanel panel2;
//private JPanel panel3;
//private JPanel panel4;
// private JPanel panel5;
//private JPanel panel6;
//private JPanel panel7;
private JLabel msgLbl;
private JLabel lbl;
private JLabel lbl2;
private JRadioButton oneB;
private JRadioButton bothB;
private JRadioButton glossB;
private JRadioButton matteB;
private JRadioButton twoDB;
private JRadioButton sevenB;
private JRadioButton wksB;
private JRadioButton reqB;
private JRadioButton dontB;
private JTextField bCTotal;
private String[] bC = {"100", "250", "500", "1000", "2000"};
private JComboBox bCQty;
private ButtonGroup radioButtonGroupSd;
private ButtonGroup radioButtonGroupQual;
private ButtonGroup radioButtonGroupDel;
private ButtonGroup radioButtonGroupDes;
private final int WINDOW_WIDTH = 300;
private final int WINDOW_HEIGHT = 200;
boolean value = true;
//double oneHun = 8.95;
//double twoFif = 11.95;
//double fiveHun = 12.95;
//double oneThou = 13.95;
//double twoThou = 27.95;
//String oneHunS = Double.toString(oneHun);
//String twoFifS = Double.toString(twoFif);
//String fiveHunS = Double.toString(fiveHun);
//String oneThouS = Double.toString(oneThou);
//String twoThouS = Double.toString(twoThou);
//double bCTot = 0;
//double bCP = 0;
//double deliv = 0;
//double sides = 0;
//double design = 0;
//String bCTotl = Double.toString(bCTot);
public BCard()
{
setTitle("Business Cards");
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buildBCPanel();
add(panel);
//add(panel2);
//add(panel3);
//add(panel4);
//add(panel5);
//add(panel6);
//add(panel7);
setVisible(value);
}
private void buildBCPanel()
{
msgLbl = new JLabel("Select the criteria that fits your needs:");
//Number of cards
lbl = new JLabel("Quantity:");
bCQty = new JComboBox(bC);
//One or both sides printed
oneB = new JRadioButton("One side");
bothB = new JRadioButton("Both sides");
//types of cards
glossB = new JRadioButton("Gloss");
matteB = new JRadioButton("Matte");
//shipping time
twoDB = new JRadioButton("Next Day");
sevenB = new JRadioButton("Seven Days");
wksB = new JRadioButton("Up to Two Weeks");
// Need us to design card?
reqB = new JRadioButton("Request Design");
dontB = new JRadioButton("Don't Require");
//Price quote
lbl2 = new JLabel("Your total may be $");
bCTotal = new JTextField(10);
bCTotal.setEditable(false);
radioButtonGroupSd = new ButtonGroup();
radioButtonGroupSd.add(oneB);
radioButtonGroupSd.add(bothB);
radioButtonGroupQual = new ButtonGroup();
radioButtonGroupQual.add(glossB);
radioButtonGroupQual.add(matteB);
radioButtonGroupDel = new ButtonGroup();
radioButtonGroupDel.add(twoDB);
radioButtonGroupDel.add(sevenB);
radioButtonGroupDel.add(wksB);
radioButtonGroupDes = new ButtonGroup();
radioButtonGroupDes.add(reqB);
radioButtonGroupDes.add(dontB);
bCQty.addActionListener(new ComboListener());
oneB.addActionListener(new RadioButtonListener());
bothB.addActionListener(new RadioButtonListener());
glossB.addActionListener(new RadioButtonListener());
matteB.addActionListener(new RadioButtonListener());
twoDB.addActionListener(new RadioButtonListener2());
sevenB.addActionListener(new RadioButtonListener2());
wksB.addActionListener(new RadioButtonListener2());
reqB.addActionListener(new RadioButtonListener());
dontB.addActionListener(new RadioButtonListener());
//bCTotal.addActionListener(new TotalListener());
//bCTotal.getDocument().addDocumentListener(new MyDocumentListener());
panel = new JPanel();
panel.add(msgLbl);
//panel2 = new JPanel();
panel.add(lbl);
panel.add(bCQty);
//panel3 = new JPanel();
panel.add(oneB);
panel.add(bothB);
//panel4 = new JPanel();
panel.add(glossB);
panel.add(matteB);
// panel5 = new JPanel();
panel.add(twoDB);
panel.add(sevenB);
panel.add(wksB);
// panel6 = new JPanel();
panel.add(reqB);
panel.add(dontB);
//panel7 = new JPanel();
panel.add(lbl2);
panel.add(bCTotal);
}
private class ComboListener implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
//turn double into string so it will show up in the JTextField
double oneHun = 8.95;
double twoFif = 11.95;
double fiveHun = 12.95;
double oneThou = 13.95;
double twoThou = 27.95;
String oneHunS = Double.toString(oneHun);
String twoFifS = Double.toString(twoFif);
String fiveHunS = Double.toString(fiveHun);
String oneThouS = Double.toString(oneThou);
String twoThouS = Double.toString(twoThou);
JComboBox comboBox=(JComboBox) e.getSource();
String s =(String) comboBox.getItemAt(comboBox.getSelectedIndex());
if(bCQty.getSelectedItem() == "100")
{
bCTotal.setText(oneHunS);
}
else if(bCQty.getSelectedItem() == "250")
{
bCTotal.setText(twoFifS);
}
else if(bCQty.getSelectedItem() == "500")
{
bCTotal.setText(fiveHunS);
}
else if(bCQty.getSelectedItem() == "1000")
{
bCTotal.setText(oneThouS);
}
else if(bCQty.getSelectedItem() == "2000")
{
bCTotal.setText(twoThouS);
}
}
}
private class RadioButtonListener implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
double oneHunB = 3.00;
double twoFifB = 1.00;
double fiveHunB = 1.00;
double oneThouB = 2.00;
double twoThouB = 4.00;
if(e.getSource() == bothB && bCQty.getSelectedItem() == "100")
{
//sides = oneHunB;
}
else if(e.getSource() == bothB && bCQty.getSelectedItem() == "250")
{
//sides = twoFifB;
}
else if(e.getSource() == bothB && bCQty.getSelectedItem() == "250")
{
//sides = fiveHunB;
}
else if(e.getSource() == bothB && bCQty.getSelectedItem() == "1000")
{
//sides = oneThouB;
}
else if(e.getSource() == bothB && bCQty.getSelectedItem() == "2000")
{
//sides = twoThouB;
}
}
}
private class RadioButtonListener2 implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
double oneHunD = 27;
double twoFifD = 29;
double fiveHunD = 33;
double oneThouD = 41;
double twoThouD = 57;
if(e.getSource() == twoDB && bCQty.getSelectedItem() == "100")
{
//deliv = oneHunD;
}
else if(e.getSource() == twoDB && bCQty.getSelectedItem() == "250")
{
//deliv = twoFifD;
}
else if(e.getSource() == twoDB && bCQty.getSelectedItem() == "500")
{
//deliv = fiveHunD;
}
else if(e.getSource() == twoDB && bCQty.getSelectedItem() == "1000")
{
//deliv = oneThouD;
}
else if(e.getSource() == twoDB && bCQty.getSelectedItem() == "2000")
{
//deliv = twoThouD;
}
}
}
//private class TotalListener implements ActionListener
{
//public void actionPerformed (ActionEvent e)
{
//bCTot = bCP + deliv + sides + design;
//bCTotal.setText(bCTotl);
}
}
public static void main(String[] args)
{
BCard bCard = new BCard();
}
}