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.*;
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("Exit",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.
49.
50.
51.
52.
53.
54.
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.
57.
58.
59.
60.
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() { }
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.
72.
73.
74.
75.
76.
77.
78.
Editor's Notes
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(); } }