GWT: using Timer as in Tread sleep()

You can use the timer to put the application to sleep, or in this case to change content every 3 seconds.



    private String currentImage = "1.png";

    private int refreshIntervalMilliseconds = 3000;

    public void onModuleLoad()
    {
params = CommonUtils.parseParamString();

Timer t = new Timer()
{
    public void run()
    {
if (currentImage.equals("1.png"))
    currentImage = "2.png";
else if (currentImage.equals("2.png"))
    currentImage = "3.png";
else if (currentImage.equals("3.png"))
    currentImage = "4.png";
else if (currentImage.equals("4.png"))
    currentImage = "1.png";
RootPanel.get("content").clear();
RootPanel.get("content").add(new Label("Current time: " + new Date()));
RootPanel.get("content").add(new Image("images/" + currentImage));
System.out.println("Putting system to sleep for " + refreshIntervalMilliseconds / 1000 + " seconds. currentImage = " + currentImage);
    }
};
t.scheduleRepeating(refreshIntervalMilliseconds);
    }


As an Amazon Associate I earn from qualifying purchases.

My favorite quotations..


“A man should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.”  by Robert A. Heinlein

"We are but habits and memories we chose to carry along." ~ Uki D. Lucas


Popular Recent Articles