Hey!
I just tried to set a new text on an image each time I press a certain key, and my program isn't working. Also, I need my text to be aligned to the top-left corner!!! Can you help me find my coding mistakes? I'd love to see whether the solution can be written in a repetitive "for" or "while" loop. Thanks!
import greenfoot.*; import java.awt.Color; public class Counter extends Actor { private static final Color transparent = new Color(0,0,0,0); private GreenfootImage back = getImage(); public String text_Mercur = "Mercury"; public String text_Venus = "Venus"; public String text_Pamant = "Earth"; public String text_Marte = "Mars"; public String text_Ceres = "Ceres"; public String text_Jupiter = "Jupiter"; public String text_Saturn = "Saturn"; public String text_Uranus = "Uranus"; public String text_Neptun = "Neptune"; public String text_Pluto = "Pluto"; public Counter() { GreenfootImage table = getImage(); table.rotate(90); table.scale(600, 400); } public void act() { GreenfootImage background = new GreenfootImage(back); if (Greenfoot.isKeyDown("1") == true) { GreenfootImage text = new GreenfootImage(text_Mercur); } else if (Greenfoot.isKeyDown("2") == true) { GreenfootImage text = new GreenfootImage(text_Venus); } else if (Greenfoot.isKeyDown("3") == true) { GreenfootImage text = new GreenfootImage(text_Pamant); } else if (Greenfoot.isKeyDown("4") == true) { GreenfootImage text = new GreenfootImage(text_Marte); } else if (Greenfoot.isKeyDown("5") == true) { GreenfootImage text = new GreenfootImage(text_Ceres); } else if (Greenfoot.isKeyDown("6") == true) { GreenfootImage text = new GreenfootImage(text_Jupiter); } else if (Greenfoot.isKeyDown("7") == true) { GreenfootImage text = new GreenfootImage(text_Saturn); } else if (Greenfoot.isKeyDown("8") == true) { GreenfootImage text = new GreenfootImage(text_Uranus); } else if (Greenfoot.isKeyDown("9") == true) { GreenfootImage text = new GreenfootImage(text_Neptun); } else if (Greenfoot.isKeyDown("0") == true) { GreenfootImage text = new GreenfootImage(text_Pluto); } GreenfootImage text = new GreenfootImage(text, 24, Color.BLACK, null); background.drawImage(text, 0, 0); setImage(background); text.clear(); } }