J2ME Overview

Chapter 9 - MIDP Game API

    J2ME Overview

  • Overview

              J2ME is a popular platform for developing games for wireless devices With MIDP 2.0.Gaming API:There are only five classes in the javax.microedition.lcdui.game package: GameCanvas, Layer, Sprite, TiledLayer, and LayerManager.

              These five classes are provide a platform for the development of games with a wide range of capabilities.

              The Layer class is the superclass of the Sprite and TiledLayer classes. This class abstracts the behavior of a visual element in a game.

              This element can be used to represents an independent graphic or a collection of graphics and animation.

              That can be moved around the game screen, or a tiled layer,which represents a graphic that can be used to create vast game backgrounds.Syntax are:

    paint(Graphics g) 

              The subclasses override the method, which has the task of rendering the elements on the screen.The LayerManager class provides a convenient mechanism to manage the various visual elements of a game.


    // main class
    public MainClass {
      private GameCanvas canvas = new MyGameCanvas();
      public MainClass() {
        // start a thread that will run infinitely
      // rest of the code
    // the actual drawing class
    public MyGameCanvas extends GameCanvas implements Runnable {
      public MyGameCanvas() {
        // instantiation code
      public void start() {
        // do initialization
     // and then start a thread
     Thread runner = new Thread(this);
      private void run() {
        // or while(keeprunning = true) 
        // where keeprunning is an instance variable
        while(true) { 
          // checks if the game has reached 
          // some boundary states or special conditions
          // gets input from user and 
          // updates instance variables 
          // that describe the games elements
          // paints elements on screen to reflect
          // the current game state using the current 
          // graphics object
          // control the rate at which screen updates are done 

© 2015 by Learncertification All Rights Reserved. The certification names are the trademarks of their respective owners. Terms & Privacy Policy