ok so heress my code... it looks the way its supposed to (except that it shows 1 zero instead of 2 while total is 0 so any additional help with that is appreciated)... it compiles correctly... but when i click on the checkboxes, the total doesnt change which is really irritating cause once this minor problem is out of the way the code is finished...
<html> <title>The Dinner Menu</title> <p align = "center"> <applet code = "DinnerMenu.class" width = "200" height = "440"> </applet> </p> </html>
import java.applet.*; import java.awt.*; import java.awt.event.*; public class DinnerMenu extends Applet implements ItemListener { int dollar = 0; int cents = 00; Label total = new Label("Dinner Price is: $" + dollar + (".") + cents); Label dm = new Label(" Dinner Menu"); Label instruct = new Label(" Please select one item from"); Label instruct2 = new Label(" each category. Your total will"); Label instruct3 = new Label(" be displayed below."); Label soupl = new Label("Soups*************************"); Label entreel = new Label("Entrees***********************"); Label dessertl = new Label("Desserts*********************"); soup watery = new soup(); entree meal = new entree(); dessert sweet = new dessert(); Font ft = new Font("Arial", Font.PLAIN, 14); Font bigft = new Font("Arial", Font.PLAIN, 28); Font boldft = new Font("Arial", Font.BOLD, 16); public void init () { setLayout(new GridLayout(0,1)); setBackground(Color.pink); dm.setFont(bigft); add(dm); this.setFont(ft); add(instruct); add(instruct2); add(instruct3); soupl.setFont(boldft); add(soupl); this.add(watery); watery.clam.addItemListener(this); watery.veg.addItemListener(this); watery.broth.addItemListener(this); entreel.setFont(boldft); add(entreel); this.add(meal); meal.chic.addItemListener(this); meal.fish.addItemListener(this); meal.beef.addItemListener(this); dessertl.setFont(boldft); add(dessertl); this.add(sweet); sweet.van.addItemListener(this); sweet.rice.addItemListener(this); sweet.cake.addItemListener(this); total.setFont(boldft); add(total); } public void itemStateChanged (ItemEvent e) { int dollarw = watery.getchangedollar(); int centsw = watery.getchangecent(); int dollarm = meal.getchangedollar(); int centsm = meal.getchangecent(); int dollars = sweet.getchangedollar(); int centss = sweet.getchangecent(); dollar = (dollarw + dollarm + dollars); cents = (centsw + centsm + centss); invalidate(); validate(); /*remove(total); total.setFont(boldft); add(total); repaint();*/ } public void paint(Graphics g) { } }
import java.applet.*; import java.awt.*; import java.awt.event.*; public class soup extends Panel implements ItemListener { CheckboxGroup soups = new CheckboxGroup(); Checkbox clam = new Checkbox("Clam Chowder",soups,false); int s11 = 2; int s12 = 79; Checkbox veg = new Checkbox("Vegetable Soup",soups,false); int s21 = 2; int s22 = 99; Checkbox broth = new Checkbox("Peppered Chicken Broth",soups,false); int s31 = 2; int s32 = 49; Font ft = new Font("Arial", Font.PLAIN, 14); public soup () { this.setVisible(true); setLayout(new GridLayout(0,1)); setBackground(Color.pink); setFont(ft); add(clam); add(veg); add(broth); } public int getchangedollar() { int x=0; if (clam.getState()==true) x=s11; else if (veg.getState()==true) x=s21; else if (broth.getState()==true) x=s31; return x; } public int getchangecent() { int x=0; if (clam.getState()==true) x=s12; else if (veg.getState()==true) x=s22; else if (broth.getState()==true) x=s32; return x; } public void itemStateChanged(ItemEvent e) { } }
import java.applet.*; import java.awt.*; import java.awt.event.*; public class entree extends Panel { CheckboxGroup ent = new CheckboxGroup(); Checkbox chic = new Checkbox("Chicken",ent,false); int e11 = 12; int e12 = 79; Checkbox fish = new Checkbox("Fish",ent,false); int e21 = 10; int e22 = 99; Checkbox beef = new Checkbox("Beef",ent,false); int e31 = 14; int e32 = 99; Font ft = new Font("Arial", Font.PLAIN, 14); public entree () { this.setVisible(true); setLayout(new GridLayout(1,0)); setBackground(Color.pink); setFont(ft); add(chic); add(fish); add(beef); } public int getchangedollar() { int x=0; if (chic.getState()==true) x=e11; else if (fish.getState()==true) x=e21; else if (beef.getState()==true) x=e31; return x; } public int getchangecent() { int x=0; if (chic.getState()==true) x=e12; else if (fish.getState()==true) x=e22; else if (beef.getState()==true) x=e32; return x; } }
import java.applet.*; import java.awt.*; import java.awt.event.*; public class dessert extends Panel { CheckboxGroup dessert = new CheckboxGroup(); Checkbox van = new Checkbox("Vanilla Ice Cream",dessert,false); int d11 = 2; int d12 = 79; Checkbox rice = new Checkbox("Rice Pudding",dessert,false); int d21 = 2; int d22 = 99; Checkbox cake = new Checkbox("Cheesecake",dessert,false); int d31 = 4; int d32 = 29; Font ft = new Font("Arial", Font.PLAIN, 14); public dessert () { this.setVisible(true); setLayout(new BorderLayout()); setBackground(Color.pink); setFont(ft); add(van, "North"); add(rice, "West"); add(cake, "East"); } public int getchangedollar() { int x=0; if (van.getState()==true) x=d11; else if (rice.getState()==true) x=d21; else if (cake.getState()==true) x=d31; return x; } public int getchangecent() { int x=0; if (van.getState()==true) x=d12; else if (rice.getState()==true) x=d22; else if (cake.getState()==true) x=d32; return x; } }
the total is supposed to change after every time you click a checkbox
thanks