
import com.nttdocomo.ui.*;
import com.nttdocomo.util.*;



public class ImageTest extends IApplication
{
	TestCanvas testCanvas = new TestCanvas();

    public void start()
	{
        Display.setCurrent(testCanvas);
		testCanvas.start();
    }
} 



class TestCanvas extends Canvas
{
	//スクリーンの大きさ
    int screenWidth;
    int screenHeight;
    
	//画像表示位置
	int gx;
	int gy;

	MediaImage mediaImage;	//メディアイメージ
	Image image;			//イメージ
	ShortTimer timer;		//タイマー

	static int TIMER_ID = 0;	//タイマーＩＤ

	public TestCanvas()
	{
		//リソース読みこみ
		try
		{
			mediaImage = MediaManager.getImage("resource:///test.gif");
			mediaImage.use();
			image = mediaImage.getImage();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}

		// スクリーンの幅と高さを取得する
		screenWidth  = getWidth();
		screenHeight = getHeight();

		// 画像の表示位置を画面の中央にする
		gx = (screenWidth  - image.getWidth() ) /2;
		gy = (screenHeight - image.getHeight()) /2;
	}

	public void start()
	{
		timer = ShortTimer.getShortTimer(this, TIMER_ID, 1000/10, true);
		timer.start();
	}

	public void paint(Graphics g)
	{
		g.lock();

		g.clearRect(0, 0, screenWidth, screenHeight);
		g.drawImage(image,gx,gy);

		g.unlock(true);
	}

	public void processEvent(int type, int param)
	{
		if( (type == Display.TIMER_EXPIRED_EVENT) && (param == TIMER_ID) )
		{
			timerLoop();
		}

		repaint();
	}

	public void timerLoop()
	{
		int key = getKeypadState();
		if( (key & (1<<Display.KEY_UP    ) ) != 0 )	gy += (-2);
		if( (key & (1<<Display.KEY_DOWN  ) ) != 0 )	gy += 2;
		if( (key & (1<<Display.KEY_LEFT  ) ) != 0 )	gx += (-2);
		if( (key & (1<<Display.KEY_RIGHT ) ) != 0 )	gx += 2;
	}

}




