Java ME CLDC MIDP

3,760 views

Published on

This PPTs explain Java ME,CLDC & MIDP in brief

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,760
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
446
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • import javax.microedition.midlet.MIDlet; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Form; public class HelloMidlet extends MIDlet implements CommandListener{ private Form form = null; private final Command cmdExit = new Command("Exit",Command.EXIT,1); public void startApp() { form = new Form("Hello World"); form.addCommand(cmdExit); form.setCommandListener(this); Display.getDisplay(this).setCurrent(form); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable d) { destroyApp(true); notifyDestroyed(); } }
  • Java ME CLDC MIDP

    1. 1.
    2. 2. Agenda <ul><li>History </li></ul><ul><li>Java Universe </li></ul><ul><li>Understanding Java ME </li></ul><ul><li>Configuration </li></ul><ul><li>Profile </li></ul><ul><li>Java ME : CLDC </li></ul><ul><li>Java ME : MIDP </li></ul>
    3. 3. History <ul><li>1990: Java started as an internal project at Sun Microsystems </li></ul><ul><li>1995: Initial release of JDK 1.0 (applets  servlets) </li></ul><ul><li>1999: JavaOne conference </li></ul><ul><li>Subdivision of Java in </li></ul><ul><ul><ul><li>Java 2 Enterprise Edition (J2EE) </li></ul></ul></ul><ul><ul><ul><li>Java 2 Standard Edition (J2SE) </li></ul></ul></ul><ul><li>Java 2 Micro Edition (Java ME) (successor of Personal Java and </li></ul><ul><li>Embedded Java) </li></ul><ul><li>2000/01 First mobile phones with support for J2ME </li></ul>
    4. 4. Java Universe
    5. 5. What is Java ME? <ul><li>Java ME : Java 2 Platform, Micro Edition </li></ul><ul><li>“ Java for small devices” </li></ul><ul><li>Java ME is downsized version on </li></ul><ul><li>J2SE </li></ul><ul><li>It is currently restricted to JRE 1.3 </li></ul><ul><li>features </li></ul><ul><li>Divided in configurations, profiles </li></ul><ul><li>and optional APIs/JSRs </li></ul>
    6. 6. Existence of Java ME <ul><li>In the early 1990s, Sun Microsystems created a new programming </li></ul><ul><li>language called Oak with cross-platform support </li></ul><ul><li>Primary focus on small handheld device with an LCD touch-screen </li></ul><ul><li>and built-in wireless networking and infrared communications </li></ul><ul><li>Market was not ready </li></ul><ul><li>Internet market was booming now oak rename java </li></ul><ul><li>It was now divided into two group J2SE & J2EE </li></ul><ul><li>After a long time demand began to grow for Java on smaller devices </li></ul><ul><li>and even on smart cards, thus returning Java to its roots. </li></ul><ul><li>J2ME born later rename it as Java ME </li></ul>
    7. 7. Advantage of Java ME <ul><li>“ Write Once, Run Anywhere” </li></ul><ul><li>Portability across the widest range of devices </li></ul><ul><li>Provide best solution for an extremely wide range of small device </li></ul><ul><li>Secure </li></ul><ul><li>Incorporation of high usability and value features </li></ul><ul><li>Easy to master </li></ul>
    8. 8. Java ME Specification
    9. 9. Configuration <ul><li>At the heart of the Java ME platform is the configuration. A configuration defines a minimal Java runtime environment suitable for a certain class or family of devices. In particular, a configuration defines: </li></ul><ul><li>The capabilities of the Java virtual machine (VM) </li></ul><ul><li>The native code that interfaces with the underlying system </li></ul><ul><li>A set of Java runtime classes for running applications </li></ul><ul><li>Minimal device requirements for memory and input/output </li></ul><ul><li>mechanisms. </li></ul>Configuration CLDC CDC
    10. 10. How CLDC, CDC Configurations came into existence <ul><li>Mobile phone , TV set-Top Boxes, Home appliances etc. having </li></ul><ul><ul><li>Limited processing power </li></ul></ul><ul><ul><li>Limited graphical capability </li></ul></ul><ul><ul><li>Limited battery power </li></ul></ul><ul><ul><li>Lower power consumption </li></ul></ul><ul><ul><li>Limited memory </li></ul></ul><ul><ul><li>Working on intermittent connection and limited bandwidth </li></ul></ul><ul><li>CLDC targeted for? </li></ul><ul><ul><li>KVM based devices </li></ul></ul><ul><li>CDC targeted for? </li></ul><ul><ul><li>JVM based devices </li></ul></ul>
    11. 11. Connected Device Configuration <ul><li>A subset of Java Standard Edition. </li></ul><ul><li>Contains almost all the libraries of Java SE except GUI related. </li></ul><ul><li>Optimized for multi-threaded low memory conditions. </li></ul><ul><ul><li>2 MB or more memory for Java platform </li></ul></ul><ul><li>Four profiles are based on CDC: </li></ul><ul><ul><ul><li>Foundation Profile </li></ul></ul></ul><ul><ul><ul><li>Personal Basis Profile </li></ul></ul></ul><ul><ul><ul><li>Personal Profile </li></ul></ul></ul><ul><ul><ul><li>Gaming Profile </li></ul></ul></ul><ul><li>Designed for Mobile & Embedded Devices with higher </li></ul><ul><li>Processing Power, Memory and Display. </li></ul><ul><li>Current Release: CDC 1.1.2 (JSR 218) </li></ul>
    12. 12. Connected Limited Device Configuration <ul><li>160 – 512K of memory available for Java. </li></ul><ul><li>Typically has limited power or battery operated. </li></ul><ul><li>Network connectivity, often wireless, intermittent, low - bandwidth. </li></ul><ul><li>Core Java class libraries available on a particular category of </li></ul><ul><li>devices.  </li></ul><ul><li>32 kilobytes memory for runtime memory allocation. </li></ul><ul><li>Two profiles are based on CLDC: </li></ul><ul><ul><li>Mobile Information Device Profile </li></ul></ul><ul><ul><li>Information Module Profile </li></ul></ul>
    13. 13. CLDC API Structure CLDC defines a core of APIs, mostly taken from the J2SE world. These include fundamental language classes in java.lang, stream classes from java.io, and simple collections from java.util. CLDC also specifies a generalized network API in javax.microedition.io.*;
    14. 14. CLDC Core API
    15. 15. Profile <ul><li>A profile is layered on top of a configuration </li></ul><ul><li>It is a collection of Java based APIs that supplement a </li></ul><ul><li>Configuration to provide capabilities for a specific vertical market or </li></ul><ul><li>device type (for example, wireless: mobile devices, set-top box etc.). </li></ul><ul><li>The main goal for a profile is to provide flexibility to the Java </li></ul><ul><li>Community while still maintaining portability across device types. </li></ul><ul><li>Profiles are defined by open industry working groups (Samsung,Nokia, </li></ul><ul><li>Sony ericsson,LG etc.)utilizing the Java Community Process Program. </li></ul><ul><li>In this way industries can decide for themselves what elements are </li></ul><ul><li>necessary to provide a complete solution targeted at their industry. </li></ul>
    16. 16. Profile <ul><li>Profiles define the application life cycle model, the user interface, </li></ul><ul><li>and access to device specific properties. </li></ul><ul><li>Java ME Profiles: </li></ul><ul><li>Mobile Information Device Profile (MIDP) </li></ul><ul><li>PDA Profile (PDAP) </li></ul><ul><li>Foundation Profile (FP), </li></ul><ul><li>Personal Profile (PP) and Personal Basic Profile (PBP). </li></ul><ul><li>RMI Profile </li></ul><ul><li>Game Profile </li></ul>
    17. 17. Java ME Family
    18. 18. KVM <ul><li>Sun's Kilobyte virtual machine </li></ul><ul><ul><li>~ 50K </li></ul></ul><ul><ul><li>With libraries + KVM ~130K </li></ul></ul><ul><li>Designed from ground up to meet needs to mobile devices </li></ul><ul><li>Highly configurable but limits us because of size restrictions </li></ul>
    19. 19. KVM Limitations <ul><li>Doesn’t support float or double data types (CLDC 1.1 does) </li></ul><ul><li>java.util greatly reduced </li></ul><ul><li>Limited string, and I/O functionality </li></ul><ul><li>No JNI or custom class loaders </li></ul><ul><li>Change in classfile verification  preverification </li></ul>
    20. 20. KVM Limitations <ul><li>java.lang subset and in some cases modified interface and </li></ul><ul><li>implementation signatures </li></ul><ul><ul><li>Runtime - Reduced signature to memory operations - freeMemory(), gc(), totalMemory()) and exit() </li></ul></ul><ul><ul><li>System (reduced signature) </li></ul></ul><ul><ul><li>Threading – Thread groups or daemon threads </li></ul></ul><ul><ul><li>Provide ~8 K of data storing facility {RMS} </li></ul></ul><ul><li>Unicode is supported, but far fewer encodings are supported </li></ul>
    21. 21. One More Glance
    22. 22. MIDP <ul><li>MIDP stands for Mobile Information Device Profile. </li></ul><ul><li>MIDP combined with the Connected Limited Device </li></ul><ul><li>Configuration (CLDC), is the Java runtime environment for </li></ul><ul><li>today's mobile information devices (MIDs) such as phones and </li></ul><ul><li>set top box. </li></ul><ul><li>Provide Graphical User Interface </li></ul><ul><li>Currently MIDP 2.0/2.1 device in market </li></ul><ul><li>A keypad, keyboard, or touch screen </li></ul><ul><ul><li>Two-way wireless networking capability </li></ul></ul><ul><ul><li>Media Support </li></ul></ul><ul><ul><li>Database support </li></ul></ul>
    23. 23. MIDP features <ul><li>Externally triggered Java ME activation is supported { SMS , </li></ul><ul><li>MMS, CBS etc} </li></ul><ul><li>Access native services {dial tel number, open system browser etc} </li></ul><ul><li>User Interface </li></ul><ul><li>Multimedia access { playing tone, songs etc} </li></ul><ul><li>Gaming API </li></ul><ul><li>Network Connectivity </li></ul>
    24. 24. MIDP Packages
    25. 25. MIDP UI Library
    26. 26. MIDlet <ul><li>What is MIDlet ? </li></ul><ul><li>A MIDlet is a MID Profile application </li></ul><ul><li>javax.microedition.midlet.MIDlet; </li></ul><ul><li>The application must extend this class to allow the application </li></ul><ul><li>management software (AMS)to control the MIDlet </li></ul><ul><li>It Allows AMS to create, start, pause, and destroy a MIDlet </li></ul>javax.microedition.midlet.MIDlet; MyApp
    27. 27. Application Management System <ul><li>AMS software must work in conjunction with the device's native </li></ul><ul><li>system software </li></ul><ul><li>Control app lifecycle </li></ul><ul><li>Starting, Stopping & Pausing </li></ul><ul><li>KVM Control by AMS </li></ul><ul><li>Java ME app run under the control of KVM </li></ul><ul><li>AMS list all the installed MIDlet on the system </li></ul><ul><li>Task done by AMS Installation, Upgrade & Version management to </li></ul><ul><li>removal of application software </li></ul>
    28. 28. AMS Action & MIDlet State
    29. 29. MIDlet lifecycle
    30. 30. MIDlet lifecycle <ul><ul><li>MIDlet belong to javax.microedition.midlet.*; package. </li></ul></ul><ul><li>Every Java ME MIDlet based on three method </li></ul><ul><ul><ul><li>startApp </li></ul></ul></ul><ul><ul><ul><li>pauseApp </li></ul></ul></ul><ul><ul><ul><li>destroyApp </li></ul></ul></ul><ul><li>startApp method </li></ul><ul><ul><ul><li>The startApp method is called when the MIDlet is started. </li></ul></ul></ul><ul><ul><ul><li>After startApp has completed, the MIDlet is in Active state. </li></ul></ul></ul><ul><ul><ul><li>It check whether any elements have been set as the current </li></ul></ul></ul><ul><ul><ul><li>screen (Display). </li></ul></ul></ul>
    31. 31. MIDlet lifecycle <ul><li>pauseApp </li></ul><ul><ul><li>MIDlet application start with pause state. </li></ul></ul><ul><ul><li>pauseApp call by external event like SMS, phone call etc. </li></ul></ul><ul><li>destroyApp </li></ul><ul><ul><li>When application wants to terminate MIDlet it calls destroyApp </li></ul></ul><ul><ul><li>MIDlet goes into the Destroyed state    </li></ul></ul><ul><ul><ul><li>destroyApp method provides unconditional parameter </li></ul></ul></ul><ul><ul><li>false MIDlet refuse to terminate </li></ul></ul><ul><ul><li>true AMS terminate the MIDlet </li></ul></ul><ul><ul><li>notifyDestroyed notifies the AMS that the MIDlet has entered </li></ul></ul><ul><ul><li>Destroyed state </li></ul></ul>
    32. 32. MIDlet lifecycle <ul><li>MIDlet </li></ul><ul><ul><li>import javax.microedition.midlet.MIDlet; </li></ul></ul><ul><ul><li>public class FirstMidlet extends MIDlet { </li></ul></ul><ul><ul><li>public void startApp() { </li></ul></ul><ul><ul><li> // MIDlet in Active State </li></ul></ul><ul><ul><li>} public void pauseApp() { </li></ul></ul><ul><ul><li> //MIDlet in Pause state </li></ul></ul><ul><ul><li>} public void destroyApp(boolean unconditional) { </li></ul></ul><ul><ul><li> //MIDlet in Destroyed state </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>} </li></ul></ul>
    33. 33. Hands On <ul><li>Hands On try it your self </li></ul>
    34. 34. <ul><li>Writing the code </li></ul><ul><ul><li>Using the text editor, enter source code, save the </li></ul></ul><ul><ul><li>code as <name>.java </li></ul></ul><ul><li>Compiling the code </li></ul><ul><ul><li><name>.class </li></ul></ul><ul><li>Pre-verification </li></ul><ul><ul><ul><li><name>.class { increase size upto 5%} </li></ul></ul></ul><ul><li>Get JAD & JAR </li></ul><ul><li>Run MIDlet on device </li></ul>Java ME Development Cycle
    35. 35. Java ME Development Cycle
    36. 36. MIDlet Suite <ul><li>The MIDlet suite is JAR & JAD file’s that contain one or more MIDlet </li></ul><ul><li>JAR=Java Archive File </li></ul><ul><li>JAD=Java Application Descriptor </li></ul><ul><li>The JAD makes information available to the application </li></ul><ul><li>manager. With this information, the manager can determine if the </li></ul><ul><li>device can accommodate the MIDlet </li></ul>
    37. 37. Inside JAR <ul><li>JSR is a production, packaged application generally consist of </li></ul><ul><li>many files. In addition to Java classes, other files such as images </li></ul><ul><li>and application data, known as resources, may be part of the </li></ul><ul><li>package. You bundle all this information together into a single entity, </li></ul><ul><li>a JAR file. </li></ul>
    38. 38. Inside JAD <ul><li>The JAD file provides information about the JAR, there are six </li></ul><ul><li>attributes that must be included into the JAD file. </li></ul><ul><li>Required six must JAD attributes: </li></ul><ul><li>MIDlet-Name -- Name of the MIDlet suite </li></ul><ul><li>MIDlet-Version -- Version number of the MIDlet </li></ul><ul><li>MIDlet-Vendor -- Who created the MIDlet </li></ul><ul><li>MIDlet-<n> -- Information about the MIDlet(s) in the suite </li></ul><ul><li>MIDlet-Jar-URL -- The URL of the JAR file </li></ul><ul><li>MIDlet-Jar-Size -- The size, in bytes, of the JAR </li></ul><ul><li>Optional attributes: </li></ul><ul><li>MIDlet-Description: </li></ul><ul><li>MIDlet-Delete-Confirm: </li></ul><ul><li>MIDlet-Install-Notify: </li></ul>
    39. 39. Inside manifest <ul><li>Reside inside the JAR file to provide the additional information about the JAR, there are six attributes that must be in the manifest file </li></ul><ul><li>Mandatory Attributes: </li></ul><ul><li>MIDlet-Name -- Name of the MIDlet suite </li></ul><ul><li>MIDlet-Version -- Version number of the MIDlet </li></ul><ul><li>MIDlet-Vendor -- Who created the MIDlet </li></ul><ul><li>MIDlet-<n> -- Information about MIDlet(s) in the suite </li></ul><ul><li>MicroEdition-Profile -- What profile is required by the MIDlet </li></ul><ul><li>MicroEdition-Configuration -- Configuration is required by the MIDlet </li></ul><ul><li>Optional attributes: </li></ul><ul><li>MIDlet-Icon: </li></ul><ul><li>MIDlet-Description: </li></ul><ul><li>MIDlet-Info-URL: Location </li></ul>
    40. 40. Over the Air
    41. 41. Over the Air <ul><li>OTA is Over the Air provisioning, users acquire the jad/jar </li></ul><ul><li>as required via their browser </li></ul><ul><li>MIDP OTA Specification </li></ul><ul><li>– Device Functionality </li></ul><ul><ul><li>Support for HTTP 1.0 or 1.1 </li></ul></ul><ul><ul><li>Discovery Application (to locate application and to </li></ul></ul><ul><ul><li>download) </li></ul></ul><ul><ul><li>AMS to manage OTA Application Provisioning life </li></ul></ul><ul><ul><li>cycle. </li></ul></ul>
    42. 42. J2ME MIDP packages <ul><li>Application Lifecycle package </li></ul><ul><ul><li>javax.microedition.midlet </li></ul></ul><ul><li>User Interface package </li></ul><ul><ul><li>javax.microedition.lcdui </li></ul></ul><ul><li>Networking package </li></ul><ul><ul><li>javax.microedition.io </li></ul></ul><ul><li>Core packages </li></ul><ul><ul><li>java.lang, java.io, java.util </li></ul></ul><ul><li>Record Management Store </li></ul><ul><ul><li>javax.microedition.rms </li></ul></ul>
    43. 43. <ul><li>MIDP UI is divided into two levels: the High-level and the </li></ul><ul><li>Low-level </li></ul>lcdui package
    44. 44. lcdui package
    45. 45. lcdui package <ul><li>User-interface classes in javax.microedition.lcdui (and </li></ul><ul><li>lcdui.games) </li></ul><ul><li>Device’s display is represented by an instance of Display. </li></ul><ul><ul><ul><li>Accessed from factory method getDisplay() </li></ul></ul></ul><ul><li>Display keeps track of what is currently visible, which is an </li></ul><ul><li>instance of Displayable </li></ul><ul><li>Current state of the screen is changed by passing </li></ul><ul><li>Displayable instances to Display’s setCurrent() method </li></ul>
    46. 46. High Level UI <ul><li>High-level API’s for high portability (Screen) </li></ul><ul><ul><li>High – level MIDlet look and feel is same on all devices </li></ul></ul><ul><ul><li>No direct access to device features </li></ul></ul><ul><ul><ul><ul><li>Color, device inputs, screen size </li></ul></ul></ul></ul><ul><ul><li>Implementation provides interaction (scrolling, navigation, drawing) </li></ul></ul><ul><ul><li>Input key event handling is not available in high-level APIs by default . </li></ul></ul><ul><li>The high-level APIs are: </li></ul><ul><ul><li>Alert - A popup screen to notify the user about an event. </li></ul></ul><ul><ul><li>Form - A screen to which Form Items can be added. The Items are also considered high-level APIs. </li></ul></ul><ul><ul><li>List - A screen containing a scrollable list of choices. </li></ul></ul><ul><ul><li>TextBox - A screen in which the user can enter or edit text. </li></ul></ul>
    47. 47. Example import javax.microedition.midlet.MIDlet; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Form; public class HelloMidlet extends MIDlet implements CommandListener{ private Form form = null; private final Command cmdExit = new Command(&quot;Exit&quot;,Command.EXIT,1); private final String name=“Hello World”; public void startApp() { form = new Form(name); form.addCommand(cmdExit); form.setCommandListener(this); Display.getDisplay(this).setCurrent(form); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable d) { destroyApp(true); notifyDestroyed(); } }
    48. 48. Event Handling <ul><li>High Level Event Handling </li></ul><ul><li>Low Level Event Handling </li></ul>
    49. 49. <ul><li>Handling events in the high-level API is based on a listener model. </li></ul><ul><ul><li>CommandListener Interface </li></ul></ul><ul><ul><li>ItemStateListener Interface </li></ul></ul><ul><li>Command - The javax.microedition.lcdui.*; package provides the </li></ul><ul><li>Command class </li></ul><ul><ul><li>Command(String label, int commandType, int priority) </li></ul></ul>High Level Event Handling
    50. 50. High Level Event Handling <ul><li>Command Type - The type specifies the command's intent. The defined </li></ul><ul><li>types are: BACK, CANCEL, EXIT, HELP, ITEM, OK, SCREEN, and STOP. </li></ul><ul><li>... </li></ul><ul><li>Command exitCommand = new Command(&quot;Exit&quot;, Command. EXIT, 1); </li></ul><ul><li>Command backCommand = new Command(&quot;Back&quot;, Command. BACK, 1); </li></ul><ul><li>Command moreCommand = new Command(&quot;More&quot;, Command.SCREEN, 2); </li></ul><ul><li>... </li></ul>
    51. 51. <ul><li>Canvas allows capturing of key-press events for most of the keys </li></ul><ul><li>available on the device. The only way to respond keyboard input is </li></ul><ul><li>by overriding the following methods </li></ul><ul><ul><li>protected void keyPressed(int keyCode) </li></ul></ul><ul><ul><li>protected void keyReleased(int keyCode) </li></ul></ul><ul><ul><li>protected void keyRepeated(int keyCode) </li></ul></ul><ul><li>Code snippet </li></ul><ul><ul><li>protected void keyPressed(int keyCode){ </li></ul></ul><ul><ul><li>//handle key code </li></ul></ul><ul><ul><li>} </li></ul></ul>Low Level Event Handling
    52. 52. Low Level Event Handling <ul><li>The minimal set of keys required by the MIDP specification to be </li></ul><ul><li>captured is: </li></ul><ul><ul><li>The digits 0 through 9 </li></ul></ul><ul><ul><li>The star or asterisk character (*) </li></ul></ul><ul><ul><li>The pound or hash character (#) </li></ul></ul><ul><li>Standard key codes </li></ul><ul><ul><li>KEY_NUM0 To KEY_NUM9 </li></ul></ul><ul><ul><li>UP ,DOWN ,LEFT ,RIGHT ,FIRE </li></ul></ul><ul><ul><li>GAME_A ,GAME_B ,GAME_C ,GAME_D </li></ul></ul>
    53. 53. <ul><li>Full control over the pixel </li></ul>Low Level UI
    54. 54. Low Level UI <ul><li>In contrast to the high-level API, the low-level API allows full </li></ul><ul><li>control of the MID display at pixel level </li></ul><ul><li>The low-level API is composed of the Canvas, Graphics </li></ul><ul><li>The Canvas and Graphics classes work together to provide low-level </li></ul><ul><li>control over a device. </li></ul><ul><li>To create your own canvas must extends your class with Canvas </li></ul><ul><li>class. </li></ul><ul><li>To writing/drawing on Canvas must implement paint method </li></ul><ul><li>public void paint(Graphics g) { </li></ul><ul><li>… </li></ul><ul><li>} </li></ul>
    55. 55. Graphics object is used by the Canvas to do all 2D geometric rendering capability. Rendering of Graphics can be done directly to the display or to an off-screen image buffer. Graphics
    56. 56. <ul><li>It provides method to handle the low level events{ key press, </li></ul><ul><li>pointer events} </li></ul><ul><li>Issue graphics object for drawing to display </li></ul><ul><li>It provides methods to identify the device's capabilities and mapping </li></ul><ul><li>of keys to game actions </li></ul><ul><li>It can register Command Listener </li></ul><ul><li>Canvas define following keys: </li></ul><ul><ul><li>KEY_NUM0,KEY_NUM1,KEY_NUM2,KEY_NUM3,KEY_NUM4, </li></ul></ul><ul><ul><li>KEY_NUM5,KEY_NUM6,KEY_NUM7,KEY_NUM8,KEY_NUM9, </li></ul></ul><ul><ul><li>KEY_STAR,KEY_POUND. </li></ul></ul>Canvas
    57. 57. <ul><li>Game action Key: </li></ul><ul><ul><li>UP,DOWN,LEFT,RIGHT,FIRE,GAME_A,GAME_B,GAME_C,and </li></ul></ul><ul><ul><li>GAME_D. </li></ul></ul><ul><li>Code snippet </li></ul><ul><li>public class MyCanvas extends Canvas{ </li></ul><ul><li>public void paint(Graphics g){ </li></ul><ul><li> g.drawString(...); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>Canvas
    58. 58. <ul><li>Key Handling </li></ul><ul><li>… </li></ul><ul><li>protected void keyPressed(int keyCode) { </li></ul><ul><li>switch (keyCode){ </li></ul><ul><li>… case Canvas.KEY_NUM3: </li></ul><ul><li>System.out.println(getKeyName(keyCode)); </li></ul><ul><li>break; </li></ul><ul><li>... </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>… </li></ul>Canvas
    59. 59. <ul><li>Game Action Key Handling </li></ul><ul><li>protected void keyPressed(int keyCode){ </li></ul><ul><li>int action = 0; </li></ul><ul><li>try { </li></ul><ul><li>action = getGameAction(keyCode); </li></ul><ul><li>switch(action){ </li></ul><ul><li>case Canvas.DOWN: </li></ul><ul><li> System.out.println(getKeyName(keyCode)); </li></ul><ul><li>break; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>Canvas
    60. 60. Canvas <ul><li>Pointer Event Handling </li></ul><ul><li>… </li></ul><ul><li>protected void pointerPressed(x, int y){ </li></ul><ul><li>if(x>0 && y<50){ </li></ul><ul><li>… . </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>… </li></ul>
    61. 61. Low Level External Interrupts Interruptions such as incoming calls to a Java ME application in a device invokes hideNotify() and showNotify() on any displaying canvas. The showNotify() method is called prior to the Canvas actually being made visible on the display, and the hideNotify() method is called after the Canvas has been removed from the display. /*called when an interrupt such as incoming call is received*/ protected void hideNotify() { } /*called when an interrupt such as incoming call is ended*/ protected void showNotify() { }
    62. 62. Example import javax.microedition.lcdui.Canvas; import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Image; public class MIDPCanvas extends Canvas implements CommandListener, Runnable { … public MIDPCanvas(DemoMidlet mid) { … } public void paint(Graphics g) { g.drawImage(offScreen, 0, 0, Graphics.LEFT | Graphics.TOP); g.drawImage(ball, ix_co, iy_co, Graphics.LEFT | Graphics.TOP); } protected void keyPressed(int keyCode) { int key = 0; try { key = getGameAction(keyCode); } catch (Exception ex) { key = keyCode; } switch (key) { case Canvas.LEFT: ix_co--; if(ix_co<0){ ix_co=0; } break; } } case Canvas.RIGHT: ix_co++; if ((ix_co + (iballWidth)) >= iScreenWidth) { ix_co = ix_co - 1; } break; case Canvas.UP: iy_co--; if(iy_co<0){ iy_co=0; } break; case Canvas.DOWN: iy_co++; if((iy_co + iballHeight)>=iScreenHight){ iy_co=iy_co-1; } break; } } }
    63. 63. Class Hierarchy of the GCF
    64. 64. Generic Connection Framework <ul><li>The CLDC has define a set of APIs for I/O called </li></ul><ul><li>the Generic Connection Framework. </li></ul><ul><li>The GCF, part of the javax.microedition.io package, </li></ul><ul><li>defines interfaces & Classes for the different kinds of I/O </li></ul><ul><li>that are possible(such as HTTP, socket, or streams ). </li></ul><ul><li>The CLDC does not actually define any I/O </li></ul><ul><li>implementations these are left to the profiles and/or the </li></ul><ul><li>OEM to define. </li></ul>
    65. 65. GCF – Protocol Support <ul><li>Its support for different connection protocols </li></ul><ul><li>Connector class is used to request to open a Connection </li></ul><ul><li>Connector.Open(&quot;protocol:address;parameters&quot;); </li></ul><ul><li>Opening various connection types </li></ul><ul><ul><li>Connector.Open(&quot;socket://…&quot;); </li></ul></ul><ul><ul><li>Connector.Open(&quot;http://...&quot;); </li></ul></ul><ul><ul><li>Connector.Open(&quot;datagram://…&quot;); </li></ul></ul><ul><ul><li>Connector.Open(&quot;file://...&quot;); </li></ul></ul>
    66. 66. GCF - example import java.io.*; import javax.microedition.io.*; … public void run() { try { HttpConnection httpConn = (HttpConnection) Connector.open(textField.getString(), Connector.READ_WRITE); InputStream inputStrem = httpConn.openDataInputStream(); int i=0; ... while((i=inputStrem.read())!=-1){ … } … inputStrem.close(); httpConn.close(); } catch (Exception ex) { ex.printStackTrace(); } } …
    67. 67. javax.microedition.lcdui.game.*;
    68. 68. <ul><li>Game package API javax.microedition.lcdui.game.*; is compact and consists of only five classes. They are: </li></ul><ul><li>Game Canvas </li></ul><ul><li>Layer </li></ul><ul><li>Layer Manager </li></ul><ul><li>Sprite </li></ul><ul><li>TiledLayer </li></ul>javax.microedition.lcdui.game.*;
    69. 69. <ul><li>Canvas Known as low-level user interface, it provides a rich variety of possibilities to draw onto the display. A class which extends Canvas has to implement the method “paint ()” with instructions that draw elements in the screen. </li></ul><ul><li>GameCanvas is a Canvas extension to simplify game development and to fix weak points from Canvas. Using GameCanvas is easier to control key events and update the screen. To control key events you just have to use the method getKeyStates() instead of using 3 methods (keyPressed, keyReleased keyRepeated) used in Canvas and to update the screen you just use flushGraphics() method. </li></ul>Canvas Vs Game Canvas
    70. 70. Canvas Vs Game Canvas Using Canvas protected void keyPressed( int keyCode) { switch (getGameAction(keyCode)) { case UP: … break ;   } protected void keyRepeated( int keyCode) { switch (getGameAction(keyCode)) { case UP: break; } Using GameCanvas Public void getEventStatus(){ int key = getKeyStates(); if ((key & LEFT_PRESSED) != 0) { …  } }
    71. 71. <ul><li>Simple record-oriented database (RMS) stored in Flash </li></ul><ul><li>memory </li></ul><ul><li>Device-independent API </li></ul><ul><li>Records are arrays of bytes that live in record stores </li></ul><ul><li>Record stores are shared within MIDlet suite </li></ul><ul><ul><li>MIDP allows for optional sharing of record stores </li></ul></ul><ul><ul><li>between MIDlet suites </li></ul></ul><ul><li>Support for enumeration, sorting, and filtering </li></ul><ul><li>Atomic update for single records </li></ul>RMS
    72. 72. <ul><li>Sharing of record stores </li></ul>RMS
    73. 73. <ul><li>Create record Store </li></ul><ul><li>To create a recordstore you can use </li></ul><ul><li>RecordStore.openRecordStore() with the second parameter set to </li></ul><ul><li>true. </li></ul><ul><li>//open record if present else create a record ... </li></ul><ul><li>RecordStore rs = null; </li></ul><ul><li>try { </li></ul><ul><li>rs = RecordStore.openRecordStore(&quot;RecordName&quot;, true); </li></ul><ul><li>} catch (Exception exe) { </li></ul><ul><li>//unable to open record or create record </li></ul><ul><li>} finally { </li></ul><ul><li>try{ </li></ul><ul><li>//to close the record store </li></ul><ul><li>rs. closeRecordStore(); </li></ul><ul><li>}catch(Exception ex){ </li></ul><ul><li>} </li></ul><ul><li>} ... </li></ul>RMS
    74. 74. <ul><li>Close Record Store </li></ul><ul><li>To close the record store you can call closeRecordStore() it will </li></ul><ul><li>close specific Record Store </li></ul><ul><ul><li>... try{ </li></ul></ul><ul><ul><li>rs. closeRecordStore(); </li></ul></ul><ul><ul><li>} catch (Exception ex){ </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>... </li></ul></ul>RMS
    75. 75. <ul><li>Add Record to RecordStore </li></ul><ul><li>To add record get bytes of record and call addRecord() to add the </li></ul><ul><li>record to the record store </li></ul><ul><li>... </li></ul><ul><li>String str= &quot;firstRecord&quot;; </li></ul><ul><li>//get bytes of record </li></ul><ul><li> byte[] rec = str.getBytes(); </li></ul><ul><li> try { </li></ul><ul><li>// added record to recordstore </li></ul><ul><li>rs.addRecord(rec, 0, rec.length); </li></ul><ul><li> } catch (Exception e) { </li></ul><ul><li>} </li></ul><ul><li>... </li></ul>RMS
    76. 76. <ul><li>Read Record from RecordStore </li></ul><ul><li>Set the array of bytes using the record size and call getRecord() </li></ul><ul><li>method to retrieve the Record Data. </li></ul><ul><li>... </li></ul><ul><li>byte[] getData; </li></ul><ul><li>try { </li></ul><ul><li>for (int i = 1; i <= rs.getNumRecords(); i++) </li></ul><ul><li>{ </li></ul><ul><li>getData = new byte[rs.getRecordSize(i)]; </li></ul><ul><li>rs.getRecord(i, getData, 0); </li></ul><ul><li>} </li></ul><ul><li>} catch (Exception exe) { </li></ul><ul><li>} </li></ul><ul><li>... </li></ul>RMS
    77. 77. <ul><li>Delete Records form Record Store </li></ul><ul><li>  To delete the record of specific id call the deleteRecord(int recordID) </li></ul><ul><li>... </li></ul><ul><li>try{ </li></ul><ul><li>for(int i=rs. getNumRecords(); i>0;i--) </li></ul><ul><li>{ </li></ul><ul><li>rs.deleteRecord(i); </li></ul><ul><li>} </li></ul><ul><li>} catch(Exception ex){ </li></ul><ul><li>} </li></ul><ul><li>... </li></ul>RMS
    78. 78. RMS <ul><li>Deleting the Record Store </li></ul><ul><li>  ... </li></ul><ul><li>private final String S_LOGIN = “loginRS”; </li></ul><ul><li>try{ </li></ul><ul><li>RecordStore.deleteRecordStore(S_LOGIN); </li></ul><ul><li>}catch(Exception ex){ </li></ul><ul><li>} </li></ul><ul><li>... </li></ul>

    ×