Hi!
I have two button and when my mouse is on one of them a text will appear under this button and disappear if I'm not on this button.
Here is the code :
The problem is that the other button does not work because I put in the else : remove all objects of the class Info ,which is the class of the text, so the text will appear but directly be removed by this else.
So I tried to remove only the object that is create when I put my mouse on this button ( the object information in the if).
here is what I change in the else :
But an error occur : cannot find symbol - variable information
So here is my question : How do I get my object information if it is in the world and then remove it without removing other object of this class ?
public void info()
{
greenfoot.MouseInfo info = Greenfoot.getMouseInfo();
if (info != null)
{
mouseX = info.getX();
mouseY = info.getY();
}
if(getX()+ largeur >= mouseX && mouseX > getX()-largeur && getY()+hauteur > mouseY && mouseY>getY()-hauteur) // variable largeur and hauteur are the height and the width of the image divided by 2
{
Info information = new Info();
String l =System.getProperty("line.separator");
information.setImage( new GreenfootImage( "...", 18, Color.BLACK, Color.WHITE));
getWorld().addObject(information,1500,320);
}
else
{
java.util.List infos = getWorld().getObjects(Info.class);
getWorld().removeObjects(infos);
}
} else
{
java.util.List infos = getWorld().getObjects(Info.class);
if(infos.contains((Object) information))
{
getWorld().removeObject(information);
}
}


