+ All Categories
Home > Technology > Session 3 J2ME Mobile Information Device Profile(MIDP) API

Session 3 J2ME Mobile Information Device Profile(MIDP) API

Date post: 14-Jan-2015
Category:
Upload: muthusvm
View: 2,582 times
Download: 7 times
Share this document with a friend
Description:
Session 3 Presentation in J2ME
Popular Tags:
32
Session :3 (30-Mar-09) - outline >> MIDP Introduction - Hardware and Software Requirements - MID Profile Architecture - MIDlet Suite >> Basics of MIDlet - MIDlet -MIDlet StateChangeException -Display -Displayable
Transcript
Page 1: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

Session :3 (30-Mar-09) - outline>> MIDP Introduction

- Hardware and Software Requirements- MID Profile Architecture- MIDlet Suite>> Basics of MIDlet- MIDlet-MIDlet StateChangeException-Display-Displayable

Page 2: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

H/W and S/W Requirement

>> H/W Requirement

-Screen size 96*54 pixels-At least one type of user input(keyboard, touch screen)-128 KB non-volatile memory for MID component.-8KB non-volatile memory for storing persistence data.-32 KB of volatile memory to running java.-Wireless N/W connectivity

Page 3: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

H/W an S/W Requirement>> S/W Requirement(OS S/W)

- Minimal scheduling, Exception handling and processing of interrupts software.- support for displaying bitmapped graphics- Must accept I/P and pass to JVM- Data Persistence S/W.- Software must be capability to read and write to/from non volatile memory.- There must be access to the networking on the device.

Page 4: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

MID Profile Architecture

Page 5: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

MID Profile Architecture

• MID- To visually portrait the architecture of the application begin with the Hardware

• Native OS – One step up running on the H/W is the Native OS.

• Native apps - first reference to an application running on an MID.

- example are configuring application (i.e. Date,Time, Ring setting)- Before J2ME only one type of apps will run in mobile that’s are native app.

Page 6: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

MID Profile Architecture (Cont.,)

• CLDC installed on the native operating system and is the foundation for the for MIDP.

• MIDP applications have access to both the libraries of CLDC and MIDP.

• OEM-specific (original equipment manufacturer) classes are provided by the manufactory of the company

Page 7: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

MIDlet Suite

• MIDlet is a java application designed to be run on a mobile device.

• It has as its core java classes the CLDC and MIDP.

• MIDlet suite consist of one or more MIDlet packaged together usings a JAR file.

Page 8: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

MIDlet suite(Cont.,)

>> Runtime environment and application manager

-- Application manager is the software on a mobile device that is responsible for installing, running and removing MIDlet suite.-- Application manager is a device – dependent software(ie., designed and implemented by Manufacture of device).

When application manager start the MIDlet , It will make all the following available to the application:-- Access to the CLDC and JVM-- Access to the MIDP-define classes : user interfaces , persistence storage ,networking support using HTTP,timer and managing user interaction with the device.-- Access to JAR file-- Access to JAD (Java Application Descriptor) file

Page 9: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

MIDlet Suite(Cont.,)>>Java Archive File (JAR)

-- Bundle all the information(Class file , images and application information) related to project into single entity known as a JAR file.-- In addition to classes and resource file , a JAR contains a file known as a manifest.-- manifest describe the content of the JAR file.-- manifest file has the name manifest.mf and is stored as the part of JAR file itself.

Page 10: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

MIDlet Suite(Cont.,)>> JAR Manifest Attributes

--Manifest has totally nine attribute , no need to define all attribute.--If the following six attribute are inside the manifest , the application manager will refuse to load the JAR:

1. MIDlet-Name2. MIDlet-Version3. MIDlet-Vendor4. MIDlet-<n>(one entry for each MIDlet in the JAR file)5. MicroEdition-Profile6. MicroEdition-Configuration

Page 11: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

MIDlet Suite(Cont.,)>> JAR –MIDlet Attribute

Page 12: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

MIDlet suite(Cont.,)

>> Sample manifest entryMIDlet-Name: Todo ListMIDlet-Version: 1.0MIDlet-Vendor: Core J2MEMIDlet-1: TodoList, /images/Todo.png, Todo.TodoMIDletMicroEdition-Profile: MIDP-1.0MicroEdition-Configuration: CLDC-1.0

Page 13: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

MIDlet Suite (Cont.,)

>>> JAD(Java Application Descriptor)>> JAD file may be available as part of the MIDlet suite to

provide information about the MIDlet(s) within the JAR.>> The rational behind including a JAD file is as follow.1. To provide information to the application manager about the

contents of a JAR. With this information, decisions can be made as to whether or not a MIDlet(s) is suitable for running on the device.

2. Provide a means for parameters to be passed to a MIDlets(s) without having to make changes to the JAR file.

Page 14: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

MIDlet Suite(Cont.,)

>> JAD Attribute-- JAD have set pre-define attribute -- You can also define your own attributes as you see necessary for your application.-- Simply create names that do not start with "MIDlet-" and you are good to go-- As with the manifest file, there is a required set of attributes that must be defined in the JAD file:1. MIDlet-Name2. MIDlet-Version3. MIDlet-Vendor4. MIDlet-<n> for each MIDlet5. MIDlet-Jar-URL

Page 15: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

MIDlet Suite(Cont.,)

Page 16: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

MIDlet Suite(Cont.,)

>> Simple JAD fileMIDlet-Name: Todo ListMIDlet-Version: 1.0MIDlet-Vendor: Core J2MEMIDlet-Jar-URL: http://www.corej2me.com/TodoMIDlet.jarMIDlet-Jar-Size: 17043MIDlet-1: TodoList, /images/Todo.png, Todo.TodoMIDlet

Page 17: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

MIDlet • MIDlet is the application that is build-upon the

MIDlet Class.• The application manager communicates with a

MIDlet through methods in this class.• This communication is a two-way street.• As an example, just as the application manager can

pause a MIDlet (e.g., to allow a user to answer an incoming phone call), a MIDlet can make a request to be paused (and later restarted).

Page 18: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

MIDlet LifeCycle• MIDP applications are known

as “MIDlets”• MIDlets move from state to

state in the lifecycle, as indicated.– Start – acquire resources and start

executing– Pause – release resources and

become quiescent (wait)– Destroy – release all resources,

destroy threads, and end all activity

Pause

Active

Destroyed

startApp

destroyApp

pauseApp

destroyApp

Page 19: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

MIDlet APIMethod Description

Communication from application manager to MIDlet

abstract void destroyApp (booleanunconditional)

MIDlet is about to be shut down

abstract void pauseApp() MIDlet is about to be placed into paused state

abstract void startApp() MIDlet has been placed into active state

Communication from MIDlet to application manager

final void notifyDestroyed() MIDlet is requesting to be shut down

final void notifyPaused() MIDlet is requesting to be paused

final void resumeRequest() MIDlet is requesting to become active (after beingpaused)

Attribute request from MIDlet to application manager

final String getAppProperty (String key) Get attributes from JAR and/or JAD files

Page 20: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

MIDlet StateChangeException

• During the course of a MIDlet's lifecycle, if an error occurs when changing states, this exception is thrown.

• Two methods(startApp(), destoryApp()) in MIDlet class are throw this Exception

Page 21: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

MIDlet StateChangeException API

Constructer Description

MIDletStateChangeException() Create exception object with no text

MIDletStateChangeException(String s) Create exception object with text

•There are two constructors for creating this exception, one with and without a text message.• Eg. TestException

Page 22: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

Display• Each MIDlet has a reference to one Display object• Retrieve information about the current display (e.g.,

the range of colors supported) and includes methods for requesting that objects (Forms, TextBoxes, etc.) be displayed.

• display controlling what is shown on the device and when

• Note- only one display object per MIDlet

Page 23: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

Creating a Display object• A Display object is made available to a MIDlet through a call to a static method

declared inside the Display class.• Structure

public class DisplayStats extends MIDlet{private Display display; // Reference to Display object// MIDlet constructorpublic DisplayStats(){display = Display.getDisplay(this);...}...}

Page 24: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

Display API• Display Class: javax.microedition.lcdui.Display

Method Description

static Display getDisplay(MIDlet m) Get Display object for this MIDlet

Displayable getCurrent() Displayable getCurrent() Get current Displayable object

void setCurrent(Alert alert, DisplayablenextDisplayable)

Show an Alert followed by the specifiedDisplayable object

void setCurrent(Displayable nextDisplayable) Show a new Displayable object

boolean isColor() Does the device support color?

int numColors() How many colors (or shades of gray) are available?

void callSerially(Runnable r) Request a runnable object be called after repainting

Page 25: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

Displayable

• Display can show any number of Displayable objects.• a Displayable object can be viewed on a device• The MIDP includes two subclasses of Displayable: Screen and

Canvas.• Screen object(Textbox, List, Form and Alert) are all high-level

user interface components, as their implementation and presentation on the device are handled for you.

• The Canvas object is used for custom graphics and low-level event handling, such as when writing games, and requires a little more finesse on your part to update the display.

Page 26: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

Creating Displayable Object

• We don't create Displayable objects directly; instead, we reference subclasses of Displayable

• Screen and Canvas extend the Displayable class• Using APIMethod Description

void addCommand(Command cmd) Add Command to Displayable object

void removeCommand(Command cmd) Remove Command from Displayable object

void setCommandListener(CommandListener l) Add CommandListener to Displayable object

boolean isShown() Is the Displayable object visible on the screen?

Page 27: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

Event Handling

• Event Handling in Mobile device• Command Object• Item Object• Command and Command Listener• Item and Item Listener

Page 28: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

Event Handling in Mobile Device

• event handling is nothing more than recognizing when an event occurs and taking an action based on that event.

• there are three key steps to successfully managing an event. - The hardware (the physical device itself) must recognize that

something has occurred.- The software on the device (the application manager) needs to be notified of the event- A message from theapplication manager will be sent to the MIDlet. This message will contain information about the event so we can make decisions as to how to proceed

Page 29: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

Command Object

• A Command is an object that holds information about an event.

• The simplest way to think of a Command is as a "button," something that you press or select

• Processing events requires a little legwork up front. Here are the steps:

1. Create a Command object to hold information about an event.2. Add the Command to a Form, Textbox, List or Canvas.3. Add a "listener" to the above Form, Textbox, and so forth.

Page 30: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

Command Object Creation

private Form fmMain; // A Formprivate Command cmExit; // A Command to exit the MIDlet...fmMain = new Form("Core J2ME"); // Form objectcmExit = new Command("Exit", Command.EXIT, 1); // Command object...fmMain.addCommand(cmExit); // Add Command to FormfmMain.setCommandListener(this); // Listen for Form events...public void commandAction(Command c, Displayable s){if (c == cmExit){destroyApp(true);notifyDestroyed();}}

Page 31: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

ItemObject• An Item is any component that can be added to a Form. ChoiceGroup,

DateField, Gauge and TextField are all subclasses of Item and each can process events.

• Items are accessible only as part of a Form, whereas Commands areavailable on Forms, as well as a Textbox, List, or Canvas.

• Once you add an Item to a Form, as with Commands, you must add a listener

• Once there is a change to an Item (e.g., a Gauge has been incremented or a DateField has been changed), the listener object will be notified (sent a message).

Page 32: Session 3 J2ME Mobile Information Device Profile(MIDP)  API

Item Listener object creation

private Form fmMain; // A Formprivate DateField dfToday; // A DateField...fmMain = new Form("Core J2ME"); // Form objectdfToday = new DateField("Today:", DateField.DATE); // DateField...fmMain.append(dfToday); // Add DateField to FormfmMain.setItemStateListener(this); // Listen for events...public void itemStateChanged(Item item){// If the datefield initiated this event…if (item == dfToday)...}


Recommended