The title is rather descriptive of what I'm trying to achieve here; I have an image and I want to be able to make a label appear that displays some text and follows the user's cursor while the mouse is over the image drawn. Here's my code:
Ideally, if there's a way to compact this down using a more efficient layout I'd be more than happy to use it as I essentially want each icon to do the exact same thing, but in a different location and using a different label depending on if its associated Boolean is true or not. I'm currently trying to get this working for just the water drop icon and was planning on copy+pasting the label-on-hover code into each if statement just to get it working.
public void drawTraits()
{
setImage(new GreenfootImage(464, 32));
GreenfootImage traitBg = getImage();
traitBg.setFont(traitBg.getFont().deriveFont(20f));
traitBg.setColor(new Color(255, 255, 255));
traitBg.drawString("Traits", 1, 24);
if(CellStats.returnWaterT() == true){
traitBg.drawImage(waterIcon, 170, 0);
MouseInfo mouse = Greenfoot.getMouseInfo();
if(mouse != null){
int mX = mouse.getX();
int mY = mouse.getY();
if(Greenfoot.mouseMoved(null)){
boolean onThis = Greenfoot.mouseMoved(this);
if(onThis){
traitBg.setFont(traitBg.getFont().deriveFont(20f));
traitBg.setColor(new Color(255, 255, 255));
traitBg.drawString("Water Transmission", mX, mY);
}
}
}
}
if(CellStats.returnLavaT() == true){
traitBg.drawImage(lavaIcon, 230, 0);
}
if(CellStats.returnRadiation() == true){
traitBg.drawImage(radiationIcon, 290, 0);
}
if(CellStats.returnZombie() == true){
traitBg.drawImage(zombieIcon, 350, 0);
}
setImage(traitBg);
}

