import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;

public class ? extends GameCanvas implements Runnable {
	public static final short SLEEP_TIME = 300;
	private ?? parent;

	public ?(?? parent) {
		super(true);
		this.parent = parent;
		Thread t = new Thread(this);
		t.start();
	}

	public void run() {
		Graphics gs = getGraphics();

		while(true) {
			if(checkGameKey()) {  //detect key in separate method
				gs.setColor(255, 255, 255);
				gs.fillRect(0, 0, this.getWidth(), this.getHeight());
				flushGraphics();  //refresh the device's display
			}
			try {
				Thread.sleep(SLEEP_TIME);
			} catch(Exception e) {
			}
		}
	}

	public boolean checkGameKey() {
		int intKey = getKeyStates();

		if( (intKey & GameCanvas.UP_PRESSED) != 0 ) {
			return true;
		} else if( (intKey & GameCanvas.DOWN_PRESSED) != 0 ) {
			return true;
		} else if( (intKey & GameCanvas.LEFT_PRESSED) != 0 ) {
			return true;
		} else if( (intKey & GameCanvas.RIGHT_PRESSED) != 0 ) {
			return true;
		} else {
			return false;
		}
	}
}
