
// instance fields
private Actor valueDisplay = new SimpleActor(); // reference to actor
private int value; // control field
​
// adding actor into world
protected void addedToWorld(World world)
{
updateValueDisplay(); // initialize image of actor
world.addObject(valueDisplay, 50, 15); // add actor to world
}
​
// method to update actor image
private void updateValueDisplay()
{
GreenfootImage image; // for new image to set to actor
/* code to create image goes here */
valueDisplay.setImage(image);
}
​
// method to change control value
public void adjustValue(int amount)
{
value += amount;
// possible code for limiting the value
{
if (value < 0) value = 0;
if (value > maximumValue) value = maximumValue;
}
updateValueDisplay();
}