Hi,
I want to delete a message after i click on the gumball machine, but I am not sure how to do it.
here is my code
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Coin extends Actor
{
public void act()
{
int mouseX, mouseY ;
if(Greenfoot.mouseDragged(this))
{
MouseInfo mouse = Greenfoot.getMouseInfo();
mouseX=mouse.getX();
mouseY=mouse.getY();
setLocation(mouseX, mouseY);
if((mouseX >= 374 && mouseX <= 417) && (mouseY >= 238 && mouseY <= 254))
{
World world;
world = getWorld();
world.removeObject(this);
Greenfoot.playSound("coinDrop.wav");
Actor msg = new Message("Coin is Inserted");
world.addObject(msg, 390, 20); // ADDED the objecj in the world
GumBallMachine machine = new GumBallMachine();
machine.getCoin(this,msg);
}
}
}
}
=========================================
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
public class Message extends Actor // To create message
{
public Message(String text)
{
GreenfootImage worldMsg = new GreenfootImage(text,20,Color.cyan,Color.black);
setImage(worldMsg);
}
}
=========================================
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.*;
/**
* Write a description of class GumBallMachine here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class GumBallMachine extends Actor
{
static public String validateCoin ;
public GumBallMachine()
{
GreenfootImage image = getImage();
image.scale(image.getWidth() - 100, image.getHeight() - 100);
setImage(image);
}
public void getCoin(Coin c, Actor msg)
{
validateCoin = c.toString();
validateCoin = validateCoin.substring(0, validateCoin.indexOf("@"));
getWorld().removeObject(msg); // WANT TO DELETE THE MSG here (but this is not working)
}
public void act()
{
if(Greenfoot.mouseClicked(this))
{
int mouseX,mouseY;
MouseInfo mouse = Greenfoot.getMouseInfo();
mouseX=mouse.getX();
mouseY=mouse.getY();
if((mouseX >= 350 && mouseX <= 420) && (mouseY >= 300 && mouseY <= 375))
{
//System.out.println(validateCoin);
Inspector inspect = new Inspector();
inspect.coinCheck(validateCoin);
}
}
}
}
Please comment if anyone knows the answer. Thank you.
