MIDP 2.0 Additions

Version 2.0 of MIDP improves the existing high-level user interface API significantly. Additionally, there are three new packages packages, javax.microedition.lcdui.game, javax.microedition.media, and javax.microedition.media.control, especially for game and multimedia programming.

LCDUI High-Level Improvements

For the high-level part of LCDUI, there are several significant additions and improvements:

  • The new Class CustomItem allows user drawn items

  • Commands can also be assigned to Items

  • All items have a new setLayout() method

The CustomItem class allows you to combine the flexibility of the low-level API directly with the high-level API on the same screen. The ability to assign commands to items allows context-sensitive menus, depending on the current focus position. For example, this could be used for nested option dialogs or to build a hypertext browser based on the high-level API only. The setLayout() method gives MIDP 2.0 applications better control over the actual layout of the items contained in a form.

The Game Package

The new game package contains graphical objects specially designed for games and animations. The class Sprite is designed for adding active objects to games. Sprites can consist of a single image or a sequence of images representing an animated sprite. In contrast to plain images, sprites have status information such as the current position and animation frame. The Sprite class also contains methods for detecting collisions with other sprites.

In addition to the Sprite, the game package contains another graphical object, the TiledLayer class. Tiled layers are large images constructed from equally sized cells and can be used for implementing a scrolling screen background, for example. The cells are obtained from a single image that is divided into a number of rows and columns, as defined by the TiledLayer constructor. Each cell contains an index that points to a tile obtained from the image given to the constructor. When the TiledLayer is displayed on the screen, the cells are rendered from the tile corresponding to the index. While positive indices are direct pointers to a portion of the source image, negative indices are indirect pointers and can be remapped for animating a set of cells with the same virtual index at once. An index of zero represents a transparent cell.

Both classes, Sprite and TiledLayer are derived from the abstract class Layer. While instances of both classes can be drawn directly using their paint method, the game package also contains a LayerManager that can manage a set of graphical objects including their Z-Order.

Finally, the game package contains the class GameCanvas, a subclass of Canvas. Each instance of GameCanvas has its own offscreen buffer. In contrast to the simple Canvas, it is safe to assume that the GameCanvas offscreen buffer is not obscured. Moreover, the GameCanvas provides access to the corresponding Graphics object outside of the paint method and a method to flush the offscreen buffer to the screen.

The Media Packages

The javax.microedition.media package contains audio support and consists of three main building blocks. The Manager class can be seen as the entry point to media access. It is able to list the supported media types and create new Player instances. A player can be used to actually play a media object, such as a midi or mp3 file (depending on the supported media types).

The code snipped below shows an example of how to play a midi file from the Web using a player object obtained from the Manager.

try {
    Player p = Manager.createPlayer("http://ringtones.org/song.mid");
    p.start();
}
catch (MediaException pe) {
}
catch (IOException ioe) {
}

The javax.microedition.media.control package contains additional components for controlling the properties of the played media objects such as volume and pitch.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset