Hey guys,
I posted something related to this before and this discussion is about the same application, but I unfortunately cannot find my previous post anymore :-(
Anyways I fixed the problem I was asking help for, but I have to write an essay about my programme and I am wondering why my first code did compile, but the image of profile.class wouldn't change. After changing one word in the code (changing Greenfoot.mouseClicked(Profile.class) to Greenfoot.mouseClicked(this) it surprisingly worked! Do you know, why it makes such a huge difference, whether I set a class or the given object as a parameter for the method?
Here are the two codes:
1) the one which didn't work
2) my final code
thank you in advance for your help!
public class Profile extends Actor
{
private GreenfootImage tickbox;
private GreenfootImage tickboxtick;
public Profile()
{
tickbox = new GreenfootImage("Tickbox.png");
tickboxtick = new GreenfootImage("Tickboxtick.png");
setImage(tickbox);
}
public void act()
{
changeImage();
}
public void changeImage()
{
if(Greenfoot.mouseClicked(Profile.class))
{
if(getImage()==(tickbox))
{
setImage(tickboxtick);
}
else
{
setImage(tickbox);
}
}
}
}
public class Profile extends Actor
{
private GreenfootImage tickbox;
private GreenfootImage tickboxtick;
public Profile()
{
tickbox = new GreenfootImage("Tickbox.png");
tickboxtick = new GreenfootImage("Tickboxtick.png");
setImage(tickbox);
}
public void act()
{
changeImage();
}
public void changeImage()
{
if(Greenfoot.mouseClicked(this))
{
if(getImage()==(tickbox))
{
setImage(tickboxtick);
}
else
{
setImage(tickbox);
}
}
}
}
