I didn't make that code, i just got it from a friend of mine... He said to me that it would work, and it did...
Here's an example of how to make the code work...
public void killCannon()
{
if (Space.cannonLife == 5)
{
Greenfoot.stop();
Space.cannonLife = 0;
Greenfoot.playSound("cdie.wav");
ScoreBoard s = new ScoreBoard(); //Means that "s" = ScoreBoard
getWorld().addObject(s, getX(), getY()-390); //Gets the ScoreBoard to pop up when the "Cannon" Dies...
}
}