I'm creating a scenario where I have a list of words in a string. The first word must drop to the bottom of the screen and disappear and then the second word appears at the top and also falls following the same process for the entire string. Unfortunately, I cannot seem to get my loop to work properly as I don't know how to make the iteration of the loop wait and allow the method to complete before cycling through to the next iteration of the loop. Here is what I have so far for code:
Can somebody please help me with this. Thank you in advance!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; /** * Write a description of class Words here. * * @author (your name) * @version (a version number or a date) */ public class Words extends Actor { private String word; private String[] randomWords = {"object"};//, "method", "class", "import", "greenfoot", "tutor", "boolean", "typing", "variable", "inheritance", "world", "actor" }; /** * */ public Words(String randomWords) { } /** * Act - do whatever the Words wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { for(int i = 0; i < randomWords.length; i++) { word = (randomWords[i]); setImage(new GreenfootImage(word,30,Color.WHITE, Color.BLACK)); if (canMove()) setLocation(getX(), getY() +2); else getWorld().removeObject(this); } } /** * Test if the letter can move forward. Return true if it can, false otherwise. */ public boolean canMove() { World myWorld = getWorld(); int y = getY(); y++; if (y >= myWorld.getHeight()-100) return false; return true; } }