I'm not familiar with mouseClicked(). I have a shopping cart assignment which involves: The ShoppingCart (actor) will be a class with no image. The class will simulate purchasing the clicked on objects and required quantity. Must have Greenfoot.mouseClicked() and quantity = Integer.parseInt(Greenfoot.ask(Enter quantity:"); I have to be able to click the item image which is on the world and have it to let the player put in the quantity. Then have the number of items they inserted and the picture show on the world.
public class ShoppingCart extends Actor
{
int quantity = 0;
double totalPrice = 0;
Actor Apple = MyWorld.grocery[0];
Actor Lemon = MyWorld.grocery[1];
Actor Strawberry = MyWorld.grocery[2];
/**
* Act - do whatever the ShoppingCart wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (Greenfoot.mouseClicked(Apple))
{
quantity = Integer.parseInt(Greenfoot.ask("Enter quantity:"));
getWorld().addObject(new Apple(),4,1);
}
}
