i have a problem with refresh (redrawing) greenfootimage. i have a class showTextField which is showing the text i want to display. right here
and i have a button which will showing some of gameobject i want to show. right here.
i have one more button which is changing the showTextField text. right here
what i want is when i click the button, the text is changing. but it wont change on display, only on debugger. i was trying about 3 hours to clear this problem. im so confuse why it wont change
public class showTextField extends Actor
{
private String text="";
public showTextField(String tks) {
GreenfootImage img = new GreenfootImage(tks, 30, Color.BLACK, new Color(0,0,0,0));
setImage(img);
}
public void redraw() {
GreenfootImage newimg = getImage();
newimg.clear();
newimg = new GreenfootImage(text, 30, Color.BLACK, new Color(0,0,0,0));
setImage(newimg);
}
public void setText() {
fillInTheBlank fib = new fillInTheBlank();
this.text = fib.lirikLagu(); //will give a random string
System.out.println(text); //checking is the text changing or not
}
}
public class startBtn extends Actor
{
/**
* Act - do whatever the startBtn wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if(Greenfoot.mouseClicked(this)) {
showTextField stf = new showTextField(new fillInTheBlank().lirikLagu());
getWorld().addObject(stf, 300, 140);
TextField textfield = new TextField();
getWorld().addObject(textfield, 292, 242);
submit submit = new submit();
getWorld().addObject(submit, 96, 350);
getWorld().removeObject(this);
}
if(Greenfoot.mouseMoved(this))
setImage("startBtnHover.png");
if(Greenfoot.mouseMoved(null) && !Greenfoot.mouseMoved(this))
setImage("startBtn.png");
}
}
public class submit extends Actor
{
private int score;
showTextField stf = new showTextField(new fillInTheBlank().lirikLagu());
public void act()
{
if(Greenfoot.mouseClicked(this)) {
stf.setText();
}
if(Greenfoot.mouseMoved(this))
setImage("submithover.png");
if(Greenfoot.mouseMoved(null) && !Greenfoot.mouseMoved(this))
setImage("submit.png");
}
private int cekLirik(String lirik, String txt) {
if(txt == lirik) {
score ++;
}
return score;
}
}
