well......after an hour of staring and trying things I come to another dead end......thank you for the help before I appreciate it but now my applet doesn't initialize....and all I get is a blank rectangle I get no errors so I'm not sure what I'm doing wrong...I'll keep working at it but if someone finds something before I do I'd appreciate it a lot
Thank you in advance
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
public class grocerystore extends Applet{
private Button order = new Button("Order");
private Label price = new Label("Your price will appear here");
private Choice food = new Choice();
private TextField quantity = new TextField();
double quantitySelected;
double eggs = 1.90;
double milk = 1.47;
double bread = 2.12;
double total;
display output = new display();
public void init() {
add(order);
add(price);
add(quantity);
add(food);
food.add("Select your food");
food.add("Eggs");
food.add("Milk");
food.add("Bread");
add(output);
output.setSize(250,100);
order.addActionListener((ActionListener)this);
food.addItemListener((ItemListener)this);
order.addActionListener((ActionListener)this);
food.addItemListener((ItemListener)this);
}
class display extends Canvas
implements ActionListener, ItemListener {
int itemSelected = food.getSelectedIndex();
public void actionPerformed(ActionEvent action) {
quantitySelected = new Double(quantity.getText()).doubleValue();
if (itemSelected==1)
total = quantitySelected * eggs;
if (itemSelected==2)
total = quantitySelected * milk;
if (itemSelected==3)
total = quantitySelected * bread;
}
public void itemStateChanged(ItemEvent event) {
if (itemSelected==1)
price.setText("The price of a dozen eggs is " + eggs);
if (itemSelected==2)
price.setText("The price of a quart of milk is " + milk);
if (itemSelected==3)
price.setText("The price of a loaf of bread is " + bread);
}
public void paint(Graphics g){
if (itemSelected==1){
g.drawString("You purchased " + quantitySelected + "dozen eggs",20,20);
g.drawString("for a total of " + total,20,30);
}
}
}
}