package com.annimon.jecp.me;

import com.annimon.jecp.ApplicationListener;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;


/**
 * 
 * @author aNNiMON
 */
public class JecpCanvas extends Canvas {
    
    private final ApplicationListener listener;
    private final Image image;

    public JecpCanvas(ApplicationListener listener) {
        this.listener = listener;
        
        setFullScreenMode(true);
        int width = getWidth();
        int height = getHeight();
        image = Image.createImage(width, height);
        Graphics g = image.getGraphics();
        
        listener.onStartApp(width, height);
        listener.onPaint(new JecpGraphics(g));
    }

    protected void paint(Graphics g) {
        g.drawImage(image, 0, 0, Graphics.TOP | Graphics.LEFT);
    }

    
    protected void keyPressed(int keyCode) {
    }

    
    protected void keyReleased(int keyCode) {
    }

    
    protected void keyRepeated(int keyCode) {
    }

    
    protected void pointerDragged(int x, int y) {
    }

    
    protected void pointerPressed(int x, int y) {
    }

    
    protected void pointerReleased(int x, int y) {
    }
}

@@ -353,19 +353,102 @@
 nal 
-Image image
+DrawingThread thread;%0D%0A    private final Image image;%0D%0A    private final JecpGraphics graphics
 ;%0D%0A%0D
@@ -740,24 +740,65 @@
 raphics();%0D%0A
+        graphics = new JecpGraphics(g);%0D%0A
         %0D%0A  
@@ -852,44 +852,106 @@
     
-listener.onPaint(new JecpGraphics(g)
+%0D%0A        thread = new DrawingThread();%0D%0A        thread.keepRunning = true;%0D%0A        thread.start(
 );%0D%0A
@@ -995,24 +995,61 @@
 phics g) %7B%0D%0A
+        listener.onPaint(graphics);%0D%0A
         g.dr
@@ -1425,32 +1425,32 @@
 %0A    %7D%0D%0A%0D%0A    %0D%0A
-
     protected vo
@@ -1492,11 +1492,432 @@
 %0A    %7D%0D%0A
+    %0D%0A    private class DrawingThread extends Thread %7B%0D%0A%0D%0A        private boolean keepRunning = true;%0D%0A%0D%0A        public void run() %7B%0D%0A            while (keepRunning) %7B%0D%0A                repaint();%0D%0A                try %7B%0D%0A                    Thread.sleep(5L);%0D%0A                %7D catch (InterruptedException ex) %7B%0D%0A                    Thread.currentThread().interrupt();%0D%0A                %7D%0D%0A            %7D%0D%0A        %7D%0D%0A    %7D%0D%0A
 %7D%0D%0A

Add Thread to Canvas