Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 14 Various MIDlet examples Rob Pooley

Similar presentations


Presentation on theme: "Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 14 Various MIDlet examples Rob Pooley"— Presentation transcript:

1 Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 14 Various MIDlet examples Rob Pooley rjp@macs.hw.ac.uk

2 Programming Handheld and Mobile devices 2 Example of TextBox 1 /* * Based on HelloMIDlet.java from Sun Microsystems * Original Author: Srikanth Raju * Changed beyond recognition by Rob Pooley */ import javax.microedition.midlet.*; import javax.microedition.lcdui.*; /** * An example MIDlet with simple TextBoxes * These allow editing of an initial text * which is then displayed in a second TextBox. */ public class HelloMIDlet extends MIDlet implements CommandListener { private Display display; // The display for this MIDlet private TextBox t1, t2; Command cExit, cDone, cRestart; public HelloMIDlet() { display = Display.getDisplay(this); }

3 Programming Handheld and Mobile devices 3 Example of TextBox 2 /** * Start up the Hello MIDlet by creating the first TextBox */ public void startApp() { t1 = new TextBox("Hello Heriot Watt", "We like Saturday!", 256, 0); cExit = new Command("Exit",Command.EXIT,0); t1.addCommand(cExit); cDone = new Command("Done",Command.OK,0); t1.addCommand(cDone); t1.setCommandListener(this); display.setCurrent(t1); } /** * Pause is a no-op since there are no background activities or * record stores that need to be closed. */ public void pauseApp() { } /** * Destroy must cleanup everything not handled by the garbage collector. * In this case there is nothing to cleanup. */ public void destroyApp(boolean unconditional) { }

4 Programming Handheld and Mobile devices 4 Example of TextBox 3 public void commandAction(Command c, Displayable d) { switch(c.getCommandType()) { case Command.EXIT: notifyDestroyed(); break; case Command.OK: t2 = new TextBox(t1.getString(), "Oh yes we do!", 256, 0); cRestart = new Command("Return",Command.BACK,0); t2.addCommand(cRestart); t2.setCommandListener(this); display.setCurrent(t2); break; case Command.BACK: startApp(); break; default: break; }

5 Programming Handheld and Mobile devices 5 Example of Alert 1 /* * * Changed beyond recognition by Rob Pooley */ import javax.microedition.midlet.*; import javax.microedition.lcdui.*; /** * An example MIDlet with simple Alerts * These allow display of an initial text and simple drawing */ public class AlertExample extends MIDlet implements CommandListener { private Display display; // The display for this MIDlet private Alert a1, a2; Command cExit, cDone, cRestart; Image i1,i2;

6 Programming Handheld and Mobile devices 6 Example of Alert 2 public AlertExample() { display = Display.getDisplay(this); } /** * Start up the Hello MIDlet by creating the first Alert */ public void startApp() { i1 = Image.createImage(30,30); Graphics g = i1.getGraphics(); g.drawLine(0,0,10,10); g.drawArc(10,10,10,10,0,360); a1 = new Alert("Hello Heriot Watt", "We like Saturday!", i1, AlertType.INFO); cExit = new Command("Exit",Command.EXIT,0); a1.addCommand(cExit); cDone = new Command("Done",Command.OK,0); a1.addCommand(cDone); a1.setCommandListener(this); display.setCurrent(a1); }

7 Programming Handheld and Mobile devices 7 Example of Alert 3 /** * Pause is a no-op since there are no background activities */ public void pauseApp() { } /** * In this case there is nothing to cleanup. */ public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable d) { switch(c.getCommandType()) { case Command.EXIT: notifyDestroyed(); break; case Command.OK: a2 = new Alert("Oh yes we do!"); cRestart = new Command("Return",Command.BACK,0); a2.addCommand(cRestart); a2.setCommandListener(this); display.setCurrent(a2); break; case Command.BACK: startApp(); break; default: break; }

8 Programming Handheld and Mobile devices 8 Example of List 1 import javax.microedition.midlet.*; import javax.microedition.lcdui.*; /** * An example MIDlet with simple Lists * These allow display of a selectable menu of strings */ public class ListExamp extends MIDlet implements CommandListener { private Display display; // The display for this MIDlet private List l1, l2; Command cExit, cDone, cRestart, cSend, cLeave; Image i1,i2; public ListExamp() { display = Display.getDisplay(this); }

9 Programming Handheld and Mobile devices 9 Example of List 2 /** * Start up the Hello MIDlet by creating the first TextBox */ public void startApp() { l1 = new List("Hello Heriot Watt",List.IMPLICIT); cExit = new Command("Exit",Command.EXIT,0); l1.addCommand(cExit); cDone = new Command("Done",Command.OK,0); l1.addCommand(cDone); cSend = new Command("Send",Command.SCREEN,0); l1.addCommand(cSend); cLeave = new Command("Leave",Command.SCREEN,0); l1.addCommand(cLeave); l1.setCommandListener(this); display.setCurrent(l1); }

10 Programming Handheld and Mobile devices 10 Example of List 3 /** * Pause is a no-op since there are no background activities or * record stores that need to be closed. */ public void pauseApp() { } /** * Destroy must cleanup everything not handled by the garbage collector. * In this case there is nothing to cleanup. */ public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable d) { switch(c.getCommandType()) { case Command.EXIT: notifyDestroyed(); break; case Command.OK: l2 = new List("Oh yes we do!",List.EXCLUSIVE); cRestart = new Command("Return",Command.BACK,0); l2.addCommand(cRestart); l2.setCommandListener(this); display.setCurrent(l2); break; case Command.BACK: startApp(); break; case Command.SCREEN: if(c.getLabel()==“Leave") notifyDestroyed(); else { Alert a1 = new Alert("Leave","Now please",null,AlertType.ERROR); display.setCurrent(a1); } break; default: break; }

11 Programming Handheld and Mobile devices 11 Example of Complex Form 1 public class CompForm extends MIDlet implements CommandListener { private Display display; // The display for this MIDlet private Form f1, f2; Command cExit, cDone, cRestart; Image i1,i2; ImageItem ii1, ii2; TextField b1, b2; public CompForm() { display = Display.getDisplay(this); } /** * Start up the Hello MIDlet by creating the Form */ public void startApp() { i1 = Image.createImage(30,30); Graphics g = i1.getGraphics(); g.drawLine(0,0,10,10); g.drawArc(10,10,10,10,0,360); i2 = Image.createImage(i1); ii1 = new ImageItem("Picture",i2,ImageItem.LAYOUT_CENT ER,"Lopsided lolly"); b1 = new TextField("text sample","1234567890",256,TextField.NUMERIC); f1 = new Form("Hello Heriot Watt"); cExit = new Command("Exit",Command.EXIT,0); f1.addCommand(cExit); cDone = new Command("Done",Command.OK,0); f1.addCommand(cDone); f1.setCommandListener(this); f1.append(ii1); f1.append(b1); display.setCurrent(f1); }

12 Programming Handheld and Mobile devices 12 Example of Complex Form 2 /** * Pause is a no-op since there are no background activities or * record stores that need to be closed. */ public void pauseApp() { } /** * Destroy must clean up everything not handled by the garbage collector. * In this case there is nothing to clean up. */ public void destroyApp(boolean unconditional) { }

13 Programming Handheld and Mobile devices 13 Example of Complex Form 3 public void commandAction(Command c, Displayable d) { switch(c.getCommandType()) { case Command.EXIT: notifyDestroyed(); break; case Command.OK: f2 = new Form("Oh yes we do!"); cRestart = new Command("Return",Command.BACK,0); f2.addCommand(cRestart); f2.setCommandListener(this); display.setCurrent(f2); break; case Command.BACK: startApp(); break; default: break; }

14 Programming Handheld and Mobile devices 14 Complex form in use

15 Programming Handheld and Mobile devices 15 Moving MIDlets There are two parts to installing MIDP for Palm OS. You must install the MIDP for Palm OS package on your desktop computer, and you must install the MIDP for Palm OS implementation (Java™ HQ) on your Palm OS device.

16 Programming Handheld and Mobile devices 16 Result of the Installation Installing the MIDP for Palm OS implementation adds the following icon to your device’s home screen:

17 Programming Handheld and Mobile devices 17 Example of TextBox 3

18 Programming Handheld and Mobile devices 18 Running applications written in Java This screen contains a copyright notice and a Preferences button. Tapping the Preferences button gives you the option to change the MIDP for Palm OS global preferences. This screen also provides help (a “tip”) if you tap the icon. Java™ HQ cannot launch Java applications. You run a Java application by tapping the application’s icon.

19 Programming Handheld and Mobile devices 19 Installing Java Applications A Java application written for MIDP is distributed as a pair of files, –one with a.jar extension and –the other with a.jad extension. Other than their extensions, the files have the same name. –For example, a poker Java application would be distributed as the files Poker.jar and Poker.jad.

20 Programming Handheld and Mobile devices 20 Converting You must convert it to a Palm OS application before you can install it. A PalmOS application is a file that has a.prc extension. You use the Convertor tool to do this.

21 Programming Handheld and Mobile devices 21 Packaging a Java application The KToolBar will package your Java MIDlet Select the Project menu Then select Package from that menu Then select Create Package from that menu The Package is created as a.jar and.jad pair in the bin folder of the project

22 Programming Handheld and Mobile devices 22 Convertor If your computer is configured to run JAR files directly, you could double-click on the Converter.jar file.

23 Programming Handheld and Mobile devices 23 To Change JAR/JAD Files Into a PRC File 1. Make sure the JAR and JAD file are in the same directory. 2. If the PRC Converter Tool is not running, start it. A window similar to the one in the following figure will appear:

24 Programming Handheld and Mobile devices 24 Using the tool 3. Click the PRC Converter Tool’s Folder button ( ), or choose Convert from its File menu. A dialog box similar to this 4. Navigate to the directory where the JAD and JAR files are located.

25 Programming Handheld and Mobile devices 25 5. Select a JAD file to convert. The JAD info panel shows you information about the Java application. Note that if your desktop computer system supports selecting multiple files in dialog boxes, you can select multiple JAD files to convert. 6. Click the Convert button to convert the JAR/JAD file pair to a PRC. (Clicking Convert does not affect the original JAR/JAD files; it merely creates a new file with a.prc extension.)

26 Programming Handheld and Mobile devices 26 Multiple MIDP for Palm OS Icons on Palm OS Device


Download ppt "Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 14 Various MIDlet examples Rob Pooley"

Similar presentations


Ads by Google