// @topic T11746 2D Graphics demo 04 -- controller and subject added
// @brief class <tt>ThreadPainter</tt> implements <tt>Runnable</tt>

package shopsimulation;

public class ThreadPainter implements Runnable {

    public static final int SLEEP_TIMEOUT = 1000 / 24; // 24 fps
    ViewDesigner mWindow;

    // constructors
    public ThreadPainter( ViewDesigner window )
    {
        mWindow = window;
    }

    @Override
    public void run() {
        for(;;) {
            // forever...
            try {
                // ask EDT thread to repaint itself
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        mWindow.getCanvas().repaint();
                    }
                });
                // go to sleep for a period of time
                Thread.sleep(SLEEP_TIMEOUT);
            } catch (InterruptedException ie) {
            }
        }
    }
}//class ThreadPainter