#ff0000 16  2005 . - #000655   Game Canvas  J2ME
#def   ,   J2ME,  .       ,   Java Community Process   MIDP 2.0    .     -  GameCanvas. 
GameCanvas     javax.microedition.lcdui.game     Canvas.   , Canvas       API,     .  Canvas  ,         ,            .     ,         .   ,   ,    . GameCanvas     ,    . 
     - ,  GameCanvas  - Canvas,      Canvas      GgameCanvas. ,  showNotify()  hideNotify()   ,  canvas   / .           GameCanvas,      .              Command  GameCanvas.     MIDlet,   canvas: 
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.GameCanvas;

public class DummyGameCanvas extends GameCanvas {

   public DummyGameCanvas( boolean suppress ){
     super( suppress );
   }

   switch( action ){
   case DOWN:
     return "DOWN";
   case UP:
     return "UP";
   case LEFT:
     return "LEFT";
   case RIGHT:
     return "RIGHT";
   case FIRE:
     return "FIRE";
   case GAME_A:
     return "GAME_A";
   case GAME_B:
     return "GAME_B";
   case GAME_C:
     return "GAME_C";
   case GAME_D:
     return "GAME_D";
   }

   return "";
   }

   protected void hideNotify(){
     System.out.println( "hideNotify" );
   }

   protected void keyPressed( int key ){
     System.out.println( "keyPressed " + key + " "
       + getAction( key ) );
   }

   protected void showNotify(){
     System.out.println( "showNotify" );
   }
}
    ,     canvas,     . -,    ,          . -,   paint(),  . , ,      DummyGameCanvas  . 
,    MIDP  ,           .  Canvas         ,             .    ,    -  .  gamecanvas   ,           :         . 
     getKeyStates().   -,       (action keys) -    Canvas -      .
int state = getKeyStates();

if( ( state & FIRE_PRESSED ) != 0 ){
       //    FIRE
}
            . ,   -  gamecanvas,     ,   .   ,        . 
 GameCanvas   .        . ,       ,         . (       "    .  "   .)          canvas.       ,    getGraphics(). (      ,               .)     ,   flushGraphics(),        . 
    .
import java.util.Random;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.GameCanvas;

//    gamecanvas,  
//   .   
//     

public class StarField extends GameCanvas
     implements Runnable {

     private static final int SLEEP_INCREMENT = 10;
     private static final int SLEEP_INITIAL = 150;
     private static final int SLEEP_MAX = 300;

     private Graphics graphics;
     private Random random;
     private int sleepTime = SLEEP_INITIAL;
     private volatile Thread thread;

     public StarField(){
          super( true );

          graphics = getGraphics();
          graphics.setColor( 0, 0, 0 );
          graphics.fillRect( 0, 0, getWidth(), getHeight() );
     }

     //  canvas    "",  thread 

     protected void hideNotify(){
          thread = null;
     }

     //  .

     public void run(){
          int w = getWidth();
          int h = getHeight() - 1;

          while( thread == Thread.currentThread() ){

               //      
               //     
               // 

               int state = getKeyStates();

               if( ( state & DOWN_PRESSED ) != 0 ){
                    sleepTime += SLEEP_INCREMENT;
                    if( sleepTime > SLEEP_MAX ) 
                         sleepTime = SLEEP_MAX;
               } else if( ( state & UP_PRESSED ) != 0 ){
                    sleepTime -= SLEEP_INCREMENT;
                    if( sleepTime < 0 ) sleepTime = 0;
               }
               //  ,  
               //       

               graphics.copyArea( 0, 0, w, h, 0, 1,
               Graphics.TOP | Graphics.LEFT );

               graphics.setColor( 0, 0, 0 );
               graphics.drawLine( 0, 0, w, 0);
               graphics.setColor( 255, 255, 255 );

               for( int i = 0; i < w; ++i ){
                    int test = Math.abs( random.nextInt() ) % 100;
                    if( test < 4 ){
                         graphics.drawLine( i, 0, i, 0 );
                    }
               }

               flushGraphics();

               // ...

               try {
                    Thread.currentThread().sleep( sleepTime );
               }
               catch( InterruptedException e ){
               }
          }
     }

     //  canvas    ,
     //   thread    .

     protected void showNotify(){
          random = new Random();

          thread = new Thread( this );
          thread.start();
     }
}
   UP  DOWN      .         . GameCanvas      .