
import com.nttdocomo.ui.*;

public class EventTest extends IApplication
{
	TestCanvas testCanvas;

    public void start()
	{
		testCanvas = new TestCanvas();
        Display.setCurrent(testCanvas);
    }
}


class TestCanvas extends Canvas
{
	//文字表示座標
	int x = 10;
	int y = 10;

	//キャンバスのサイズ
	int screenWidth  = getWidth();
	int screenHeight = getHeight();

	public void paint(Graphics g)
	{
		g.lock();	//ロック

		g.clearRect(0, 0, screenWidth, screenHeight);	//クリア
		g.drawString("Hello World!", x, y);

		g.unlock(true);	//アンロック
	}

	public void processEvent(int type, int param)
	{
		System.out.println("EVENT: type=" + type + " param=" + param);

		if( type == Display.KEY_PRESSED_EVENT)	//キー押しイベントだったら
		{
			switch(param)
			{
				case Display.KEY_UP:	y +=(-4);	break;
				case Display.KEY_DOWN:	y += 4;		break;
				case Display.KEY_LEFT:	x +=(-4);	break;
				case Display.KEY_RIGHT:	x += 4;		break;
			}

			repaint();
		}
	}
}

