
import	javax.microedition.lcdui.*;

public class PolyCanvas extends Canvas implements TimerListener
{
	//	オブジェクトたち
	final int[] dot_x = { 0 };
	final int[] dot_y = { 0 };

	final int[] line_x = { -10, 20 };
	final int[] line_y = { -12, 15 };

	final int[] tri_x = { 0, -20, 30 };
	final int[] tri_y = { -12, 15, 16 };

	final int[] sq_x = {  10, -10, -10, 10 };
	final int[] sq_y = { -10, -10,  10, 10 };

	final int[] hex_x = {  2, 12, 14,  0, -9, -11 };
	final int[] hex_y = { 13,  5, -4, -11, -2, 6 };

	MoveObj	objroot;

	boolean	update = true;

	//
	private	Image	offscr;
	private	Graphics	offg;

	PolyCanvas()
	{
		offscr = Image.createImage( getWidth(), getHeight() );
		offg = offscr.getGraphics();
		offg.setColor( 255, 255, 255 );
		offg.fillRect( 0, 0, getWidth(), getHeight() );

		objroot = new MoveObj( new Polygon( 1, dot_x, dot_y, 0x000000 ),
									getWidth(), getHeight() );

		objroot.add( new MoveObj( new Polygon( 2, line_x, line_y, 0x400000 ),
									getWidth(), getHeight() ) );

		objroot.add( new MoveObj( new Polygon( 3, tri_x, tri_y, 0xFF0000 ),
									getWidth(), getHeight() ) );

		objroot.add( new MoveObj( new Polygon( 4, sq_x, sq_y, 0x009000 ),
									getWidth(), getHeight() ) );

		objroot.add( new MoveObj( new Polygon( 6, hex_x, hex_y, 0x0090FF ),
									getWidth(), getHeight() ) );
	}

	public void paint( Graphics g )
	{
		if( offg == null )
		{
			return;
		}

		g.drawImage( offscr, 0, 0, g.LEFT | g.TOP );
		if( update )
		{
			offg.setColor( 255, 255, 255 );
			offg.fillRect( 0, 0, getWidth(), getHeight() );

			if( objroot != null )
			{
				objroot.move( getWidth(), getHeight() );
				objroot.draw( offg );
			}

			offg.setColor( 64, 64, 0 );
			offg.drawString( "Testだよーーーん!", 0, 0, offg.LEFT | offg.TOP );

			update = false;
		}
	}

	public void timeout()
	{
		if( offg == null )
		{
			return;
		}

		update = true;

		repaint();
	}
}

