Animation without additional thread, Using SwingUt

There is a little hint to those who programs animation in java. The common technique is to create separate thread in which the animation loop is running. But it is possible to avoid thread creation and run animation loop directly in main thread (that is awt event dispatch thread). The main idea is to use method SwingUtilities.invokeLater to avoid blocking of main thread.

Here is code sample:


public class MyApplet extends JApplet implements Runnable {

    private boolean moving;

    public void start() {
        moving = true;
        run();
    }

    public void stop() {
        moving = false;
    }

    public void run() {
        if (moving) {
            nextCycle();
            //temporarily returning control to AWT thread
            //allowing all ui events to be delivered
            SwingUtilities.invokeLater(this);
        }
    }

    public void nextCycle() {
        //All animation is performed here
    }
}

Really simple! No synchronization needed, no notify/wait.

You can see working examples of this approach on my applets page:
http://coolapps.hut1.ru

I’m a little confused as to what the advantage of this technique is. Can you clarify how this is better, (or what the pros and cons are), than creating my own thread and performing the game logic and rendering every time through my main loop? Where is the time control in your code? I am also confused by what you said about notify/wait. I have never needed to use notify() or wait() in any of my games - either I am uninformed or they are unnecessary for most games. When using one thread for both rendering and game logic, (which seems to be standard for most of the developers here), there should be no need for notify/wait or synchronization.