This site requires JavaScript, please enable it in your browser!
Greenfoot back
BlueHand
BlueHand wrote ...

2021/6/8

How to get rid of text?

BlueHand BlueHand

2021/6/8

#
Hello! I have an arraylist and constructor in my Questions class! There are five questions in the constructor. After I make one appear, how do I make the previous question disappear?
public class Questions extends Actor
{
    private ArrayList<String> questionList = new ArrayList<String>();
    Instructions instruct;
    private String newImage;
    private int index = 0;
    private Truebutton myTrueButton;
    private Falsebutton myFalseButton;
    /**
     * Act - do whatever the Questions wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if(myTrueButton.clicked() || myFalseButton.clicked())
        {
            index++;//remember to check if index is equal to 5 or greater then done with program
            display();
        }
    }   
    
    public String show()
    {
        return questionList.get(index);
    }    
    /**
     * display - gets the next question
     */
    public void display() 
    {
        World myWorld = getWorld();
        Greenfoot.delay(10);
        myWorld.getBackground().drawImage(new GreenfootImage(show(), 20, null, null), 15, 150);
        
    } 
    
    public Questions(Truebutton tbutton, Falsebutton fbutton)
    {
        myTrueButton = tbutton;
        myFalseButton = fbutton;
        getImage().setTransparency(0);
        questionList.add("Covid-19 can be transmitted through the air.");
        questionList.add("Covid-19 particles last for weeks on surfaces.");
        questionList.add("Loss of smell is a symptom.");
        questionList.add("Younger people are at higher risk.");
        questionList.add("Reinfection is not possible.");
        instruct=new Instructions(show());
    }
}
You need to login to post a reply.