| | |
Cannot figure out why I'm getting these Errors
![]() |
•
•
Join Date: Apr 2004
Posts: 5
Reputation:
Solved Threads: 0
WOOOOO I figured it out....I got it to initialize and I got my choicebox to work whoohooo
now I just gotta work on manipulating my canvas to work when my button is pressed.....but it's 3 am and I've been working on this since midnight just like everyother night this week...thank you for all you help and Bounty here is the code
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(3);
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(quantity);
add(food);
food.add("Select your food");
food.add("Eggs");
food.add("Milk");
food.add("Bread");
add(price);
add(output);
output.setSize(300,300);
food.addItemListener(this.output);
order.addActionListener(this.output);
}
class display extends Canvas
implements ActionListener, ItemListener {
public int itemSelected;
public void actionPerformed(ActionEvent action) {
quantitySelected = new Double(quantity.getText()).doubleValue();
itemSelected = food.getSelectedIndex();
if (itemSelected==1)
total = quantitySelected * eggs;
if (itemSelected==2)
total = quantitySelected * milk;
if (itemSelected==3)
total = quantitySelected * bread;
}
}
public void itemStateChanged(ItemEvent event) {
itemSelected = food.getSelectedIndex();
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",50,50);
g.drawString("for a total of " + total,50,60);
}
}
}
now I just gotta work on manipulating my canvas to work when my button is pressed.....but it's 3 am and I've been working on this since midnight just like everyother night this week...thank you for all you help and Bounty here is the code
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(3);
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(quantity);
add(food);
food.add("Select your food");
food.add("Eggs");
food.add("Milk");
food.add("Bread");
add(price);
add(output);
output.setSize(300,300);
food.addItemListener(this.output);
order.addActionListener(this.output);
}
class display extends Canvas
implements ActionListener, ItemListener {
public int itemSelected;
public void actionPerformed(ActionEvent action) {
quantitySelected = new Double(quantity.getText()).doubleValue();
itemSelected = food.getSelectedIndex();
if (itemSelected==1)
total = quantitySelected * eggs;
if (itemSelected==2)
total = quantitySelected * milk;
if (itemSelected==3)
total = quantitySelected * bread;
}
}
public void itemStateChanged(ItemEvent event) {
itemSelected = food.getSelectedIndex();
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",50,50);
g.drawString("for a total of " + total,50,60);
}
}
}
•
•
Join Date: Jul 2004
Posts: 3
Reputation:
Solved Threads: 0
I think if you changed "grocerystore.java" to "grocerystore.class" you might get it to display in your browser.
•
•
•
•
Originally Posted by Defiledgrave
<html>
<body>
<applet code="grocerystore.java"width="250"height="250">
</applet>
</body>
</html>
that is the html code I'm using.....it's a simple webpage used to just test the code I'm getting a cast exception on line 30 and 31 which are the addActionListener and the addItemListener....I don't know why I can't figure it out.....:-( I e-mailed my professor with the question...I'm gonna see what he has to say about it.....and I'll work on it some more....if you looked at it some more that would be great one of these times my eyes are going to start bleeding from staring too long.......
![]() |
Similar Threads
- VC++ 6.0 errors (C++)
- compilation errors (C++)
Other Threads in the Java Forum
- Previous Thread: help to set up "Sun Java™ System Application Server PE 8" for web application
- Next Thread: java code newbie
| Thread Tools | Search this Thread |
6 @param actuate affinetransform android api applet application arc array automation balls binary bluetooth bold business c++ class client code codesnippet collections color compare component coordinates database defaultmethod detection doctype dragging ebook eclipse educational error file fractal froglogic game givemetehcodez graphics gridlayout gui guitesting helpwithhomework html ide ideas image ingres intersect invokingapacheantprogrammatically j2me java java.xls javaexcel javaprojects jni jpanel jtextarea julia keytool keyword linux list map method methods mobile mysql netbeans nextline object parameter php pong problem producer program project projectideas recursive replaysolutions rim scanner sell server set size sms sql sun swing swt terminal threads tree web websites windows






glad to here you got it working