this program is ordering pizza. program works well. but i theres one glitch not really but for my needs thats when u run it and open in html you will see "1st topping is free",
how can i make that 1st topping(any) free of charge?
so far im just charging all the toppings for there fisrt choose
CODE
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.text.DecimalFormat;
public class ApPizza extends JApplet implements ItemListener
{
//TOPPINGS
private JCheckBox cheeseTopCB, pepTopCB, hamTopCB, sausTopCB, pineTopCB,
baconTopCB;
//SIZES
private JRadioButton smallRB, mediumRB, largeRB;
private ButtonGroup sizeSelectBG;
//COST OF TOPPINGS
private double toppings = 1.50;
//TOTAL AMOUNT
private double cost = 0;
public void init()
{
Container c = getContentPane();
c.setLayout(null);
cheeseTopCB = new JCheckBox("Extra Cheese");
pepTopCB = new JCheckBox("Pepperoni");
hamTopCB = new JCheckBox("Ham");
sausTopCB = new JCheckBox("Sausage");
pineTopCB = new JCheckBox("Pineapple");
baconTopCB = new JCheckBox("Bacon");
smallRB = new JRadioButton("Small $4.99");
mediumRB = new JRadioButton("Med. $9.99");
largeRB = new JRadioButton("Large $12.99");
cheeseTopCB.setSize(100,30);
pepTopCB.setSize(100,30);
hamTopCB.setSize(100,30);
sausTopCB.setSize(100,30);
pineTopCB.setSize(100,30);
baconTopCB.setSize(100,30);
smallRB.setSize(100,30);
mediumRB.setSize(100,30);
largeRB.setSize(100,30);
cheeseTopCB.setLocation(50,150);
pepTopCB.setLocation(50,170);
hamTopCB.setLocation(50,190);
sausTopCB.setLocation(170,150);
pineTopCB.setLocation(170,170);
baconTopCB.setLocation(170,190);
smallRB.setLocation(170,50);
mediumRB.setLocation(170,70);
largeRB.setLocation(170,90);
cheeseTopCB.addItemListener(this);
pepTopCB.addItemListener(this);
hamTopCB.addItemListener(this);
sausTopCB.addItemListener(this);
pineTopCB.addItemListener(this);
baconTopCB.addItemListener(this);
smallRB.addItemListener(this);
mediumRB.addItemListener(this);
largeRB.addItemListener(this);
c.add(cheeseTopCB);
c.add(pepTopCB);
c.add(hamTopCB);
c.add(sausTopCB);
c.add(pineTopCB);
c.add(baconTopCB);
c.add(smallRB);
c.add(mediumRB);
c.add(largeRB);
sizeSelectBG = new ButtonGroup();
sizeSelectBG.add(smallRB);
sizeSelectBG.add(mediumRB);
sizeSelectBG.add(largeRB);
}
public void paint(Graphics g)//THE STRINGS BEING CREATED
{
DecimalFormat blah = new DecimalFormat("0.00");
super.paint(g);
g.setFont(new Font("Comic Sans",Font.PLAIN, 24));
g.drawString("Welcome to PizzaStuff", 30,30);
g.setFont(new Font("Comic Sans",Font.BOLD, 14));
g.drawString("Choose Size:", 30,75);
g.setFont(new Font("Comic Sans",Font.BOLD, 14));
g.drawString("Choose Toppings:$1.50 per Topping(1st topping Free)", 30,150);
g.setFont(new Font("Comic Sans",Font.BOLD, 14));
g.drawString("Total: $" +blah.format(cost), 200,300);
}
public void itemStateChanged(ItemEvent e)
{
//TOPPING BUTTONS
if(e.getSource() == cheeseTopCB)
{
if(e.getStateChange() == ItemEvent.SELECTED)
cost = cost + toppings;
if(e.getStateChange() == ItemEvent.DESELECTED)
cost = cost - toppings;
}
if(e.getSource() == pepTopCB)
{
if(e.getStateChange() == ItemEvent.SELECTED)
cost = cost + toppings;
if(e.getStateChange() == ItemEvent.DESELECTED)
cost = cost - toppings;
}
if(e.getSource() == hamTopCB)
{
if(e.getStateChange() == ItemEvent.SELECTED)
cost = cost + toppings;
if(e.getStateChange() == ItemEvent.DESELECTED)
cost = cost - toppings;
}
if(e.getSource() == sausTopCB)
{
if(e.getStateChange() == ItemEvent.SELECTED)
cost = cost + toppings;
if(e.getStateChange() == ItemEvent.DESELECTED)
cost = cost - toppings;
}
if(e.getSource() == pineTopCB)
{
if(e.getStateChange() == ItemEvent.SELECTED)
cost = cost + toppings;
if(e.getStateChange() == ItemEvent.DESELECTED)
cost = cost - toppings;
}
if(e.getSource() == baconTopCB)
{
if(e.getStateChange() == ItemEvent.SELECTED)
cost = cost + toppings;
if(e.getStateChange() == ItemEvent.DESELECTED)
cost = cost - toppings;
}
//PIZZA SIZES IN RADIOBUTTON
if(e.getSource() == smallRB)
{
if(e.getStateChange() == ItemEvent.SELECTED)
cost = cost + 4.99;
if(e.getStateChange() == ItemEvent.DESELECTED)
cost = cost - 4.99;
}
if(e.getSource() == mediumRB)
{
if(e.getStateChange() == ItemEvent.SELECTED)
cost = cost + 9.99;
if(e.getStateChange() == ItemEvent.DESELECTED)
cost = cost - 9.99;
}
if(e.getSource() == largeRB)
{
if(e.getStateChange() == ItemEvent.SELECTED)
cost = cost + 12.99;
if(e.getStateChange() == ItemEvent.DESELECTED)
cost = cost - 12.99;
}
repaint();
}
}
html
CODE
<html>
<head>
<title>BUY PIZZA</title>
<body>
<object code = "ApPizza.class" width = 600 height = 480>
</object>
</body>
</html>