Walk.java



import com.nttdocomo.ui.*;
public class Walk extends IApplication implements Runnable {
    public Image[] images = new Image[8];
    public MediaImage[] mis = new MediaImage[8];
    public Thread thread = null;
    public ZouCanvas canvas;

    public void start() {
        try {
            for( int i=0; i<8; i++ ) {
                mis[i]
                   = MediaManager.getImage( 
                   "resource:///walk" + (i+1) + ".gif" );
                mis[i].use();
                images[i] = mis[i].getImage();
            }
            canvas = new ZouCanvas();
            Display.setCurrent( canvas );
            canvas.setSoftLabel( Frame.SOFT_KEY_1, "" );
            canvas.setSoftLabel( Frame.SOFT_KEY_2, "Stop" );
            thread = new Thread( this );
            thread.start();
        }
        catch( Exception e ){
        }
    }

    public void run() {
       try {
            while( thread.isAlive() ) {
               if( canvas.runFlag ) {
                   canvas.repaint();
               }
               Thread.sleep( 200 );
            }
       }
       catch( Exception e ) {
       }
    }

    class ZouCanvas extends Canvas {

        public boolean runFlag = true;
        public boolean firstFlag = true;
        public int counter = 0;
        public int w=0;
        public int h=0;
        public int iw=0;
        public int ih=0;
        public int x=0;
        public int y=0;
        public int d=8;

        public void paint( Graphics g ) {
            if( firstFlag == true ) {
                w = Display.getWidth();
                h = Display.getHeight();
                iw = images[0].getWidth();
                ih = images[0].getHeight();
                y = (h-ih)/2;
                x = (w-iw)/2;
                firstFlag = false;
            }
            else {
                x += d;
                if( x > w )
                  x = -w;
            }
            g.clearRect( x-d, y, d, ih );
            g.drawImage( images[ counter ], x, y );
            counter = (counter+1)%8;
        }

        public void processEvent( int type, int param ) {
            if( type == Display.KEY_PRESSED_EVENT ) {
                if( param == Display.KEY_SOFT1 ) {
                    runFlag = true;
                    setSoftLabel( Frame.SOFT_KEY_1, "" );
                    setSoftLabel( Frame.SOFT_KEY_2, "Stop" );
                }
                else if( param == Display.KEY_SOFT2 ) {
                    runFlag = false;
                    setSoftLabel( Frame.SOFT_KEY_1, "Start" );
                    setSoftLabel( Frame.SOFT_KEY_2, "" );
                }
            }
        }

    }
}