Hi
i am new to greenfoot and i am trying to create a game where there are two values the user needs to enter. i have taken the following code and it allows me to write in a box (credit to danpost as i found this on another discussion)
static final int MAX_INPUT_WIDTH = 20;
String text = "-8,8";
public Move_up()
{
updateImage();
text = "";
}
private void updateImage()
{
GreenfootImage image = new GreenfootImage(15*MAX_INPUT_WIDTH, 30);
image.setColor(new Color(128, 0, 0));
image.fill();
image.setColor(Color.lightGray);
image.fillRect(3, 3, image.getWidth()-6, 24);
GreenfootImage textImage = new GreenfootImage(text, 24, Color.black, null);
image.drawImage(textImage, (image.getWidth()-textImage.getWidth())/2, 15-textImage.getHeight()/2);
setImage(image);
}
public void act()
{
String key = Greenfoot.getKey();
if (key == null) return;
if ("enter".equals(key) && text.length() > 0)
{
return;
}
if ("backspace".equals(key) && text.length() > 0) text = text.substring(0, text.length() - 1);
if ("escape".equals(key)) text = "";
if ("space".equals(key)) key = " ";
if (key.length() == 1 && text.length() < MAX_INPUT_WIDTH) text += key;
updateImage();
}
this works but i can then not click on to my other box to change the data in that one. It is the same code. If you could help me out that would be great! also if i want to call the string at a later date how would i do that, what is it stored as. e.g. later on i change a value to the value the user has inputted.


