Thanks, davmac. I do not know what lead me to believe that, as I have always used 'getImage' for the actors. I sit corrected with fp.


public class Screen extends Body { public Screen() { setText(""); } /** * */ public void setText(String text) { GreenfootImage image = new GreenfootImage(136, 88); image.setColor(Color.white); image.fill(); int fontSize = 20; GreenfootImage txtImg = new GreenfootImage(text, fontSize, Color.blue, Color.white); int across = (image.getWidth() - txtImg.getWidth()) / 2; int down = (image.getHeight() - txtImg.getHeight()) / 2; image.drawImage(txtImg, across, down); setImage(image); } }
public class Money extends Actor { private int credit; /** * Act - do whatever the Money wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public int getValue() { return credit; } }
public ChocolateDispenser() { super(722, 640, 1); prepareBody(); prepareKeyboard(); prepareMoney(); prepareChocolates(); preparePrices(); [i][u]Screen screen = (Screen) getObjects(Screen.class).get(0);[/u][/i] }
public class FiftyPence extends Money { private int value = 50; private long markTime = 0; GreenfootImage image = null; /** * */ public void act() { if (markTime == 0 && Greenfoot.mouseClicked(this)) { setLocation(517, 314); credit(); markTime = System.currentTimeMillis(); } if (markTime != 0 && System.currentTimeMillis() - markTime > 1000) { markTime = 0; setLocation(555, 453); } } /** * */ private void credit() { ((Screen) getWorld().getObjects(Screen.class).get(0)).setText("Credit: " + value); } }
public class Counter extends Actor { private int value; private boolean moneyFound = false; /** * Act - do whatever the Counter wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { coinFound(); noteFound(); getCredit(); update(); } /** * Counting all Coins in Money class, which are inserted into the Coin Insertion. */ public void coinFound() { if (!moneyFound && !getWorld().getObjectsAt(517, 314, Money.class).isEmpty()) { moneyFound = true; Money money = (Money) getWorld().getObjectsAt(517, 314, Money.class).get(0); value += money.getValue(); } if (moneyFound && getWorld().getObjectsAt(517, 314, Money.class).isEmpty()) { moneyFound = false; } } /** * Counting all Notes in Money class, which are inserted into the Note Insertion. */ public void noteFound() { if (!moneyFound && !getWorld().getObjectsAt(517, 314, Money.class).isEmpty()) { moneyFound = true; Money money = (Money) getWorld().getObjectsAt(517, 314, Money.class).get(0); value += money.getValue(); } if (moneyFound && getWorld().getObjectsAt(517, 314, Money.class).isEmpty()) { moneyFound = false; } } /** * */ public int getCredit() { return value; } /** * */ public void update() { ((Screen) getWorld().getObjects(Screen.class).get(0)).setText("Credit: " + value); } }