Basics of J2ME - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Basics of J2ME

Description:

Introduction to programming in J2ME Basics of J2ME Objectives Understand the AMS states and lifecycle Understand a simple Hello World program Appreciate different ... – PowerPoint PPT presentation

Number of Views:18
Avg rating:3.0/5.0
Slides: 11
Provided by: DavidGil
Category:
Tags: j2me | basics | j2me

less

Transcript and Presenter's Notes

Title: Basics of J2ME


1
Introduction to programming in J2ME
2
Basics of J2ME
  • Objectives
  • Understand the AMS states and lifecycle
  • Understand a simple Hello World program
  • Appreciate different command objects
  • Appreciate different command types
  • Appreciate J2ME user-interface API class
    hierarchy

2
2
3
Mobile Information Device Profile (MIDP)
  • MIDP device contains a program called the
    application management software (AMS) which
    downloads the MIDlet suite from the server, opens
    the MIDlet suite, then launches the
    user-specified MIDlet on the MIDP device
  • LifeCycle of a midlet

constructor method called
paused state
startApp method called
pauseApp method called
active state
destroyApp method called
4
A simple program
  • import javax.microedition.midlet.
  • import javax.microedition.lcdui.
  • public class HelloWorld extends MIDlet
  • private Form form
  • private Display display
  • public HelloWorld()
  • super()
  • public void startApp()
  • form new Form("A simple MIDlet")
  • String msg "Hello, World"
  • form.append(msg)
  • display Display.getDisplay(this)
  • display.setCurrent(form)

5
The same program
  • import javax.microedition.midlet.
  • import javax.microedition.lcdui.
  • public class HelloWorld extends MIDlet
  • private Form form
  • private Display display
  • public HelloWorld()
  • form new Form("A simple MIDlet")
  • String msg "Hello, World"
  • form.append(msg)
  • display Display.getDisplay(this)
  • public void startApp()

6
Command Objects
  • Soft-Buttons and keys
  • Create a command object
  • private Command cmHelp
  • cmHelp new Command("Help", Command.HELP, 1)
  • Add the command object to a form
  • fmMain.addCommand(cmHelp)
  • Add a listener to the form
  • fmMain.setCommandListener(this)
  • Perform an action
  • public void commandAction(Command c,
    Displayable s)
  • if (c cmHelp)
  • display.setCurrent(tbHelp)

7
Command types
  • BACK
  • CANCEL
  • EXIT
  • HELP
  • ITEM
  • A request to map the Command to an item on the
    screen. E.g. when using a List component, you can
    mimic the functionality of a context-sensitive
    menu by mapping Commands to the various entries
    In the list
  • OK
  • SCREEN
  • For commands in which it is unlikely there will
    be a specific key mapping available. For example
    you might have Commands to initiate uploading and
    downloading of data. The labels Upload and
    Download will not have direct key mappings on
    the a device
  • STOP

8
  • import javax.microedition.midlet.
  • import javax.microedition.lcdui.
  • public class CommandExample extends MIDlet
    implements CommandListener
  • private Display display // Reference to
    Display object for this MIDlet
  • private Form form // Main Form
  • private TextBox texthelp // Textbox to
    display help message
  • private Command exit // Exit the MIDlet
  • private Command help // Ask for Help
  • private Command back // Go "back" to the
    main form
  • public CommandExample()
  • display Display.getDisplay(this)
  • help new Command("Help", Command.HELP, 1)
  • back new Command("Back", Command.BACK, 1)
  • exit new Command("Exit", Command.EXIT, 1)

9
  • import javax.microedition.midlet.
  • import javax.microedition.lcdui.
  • public class ManyCommands extends MIDlet
    implements CommandListener
  • private Display display // Reference to
    Display object for this MIDlet
  • private Form form // The main Form
  • private TextBox feedback // Textbox to
    show different messages
  • private Command exit // Exit the MIDlet
  • private Command back // Go "back" to the
    main form
  • private Command displayMessage1 //
    message1
  • private Command displayMessage2 //
    message2
  • public ManyCommands()
  • display Display.getDisplay(this)
  • exit new Command("Exit", Command.EXIT, 1)
  • back new Command("Back", Command.BACK, 1)
  • displayMessage1 new Command("Message1",
    Command.SCREEN, 2)

10
J2ME user-interface API class hierarchy
javax.microedition.lcdui.Displayable
(High Level)
(Low Level)
Canvas
Screen
Alert
Form
TextBox
List
Item
ChoiceGroup
DateField
ImageItem
StringItem
TextField
Guage
Write a Comment
User Comments (0)
About PowerShow.com