Developing Applications for Palm Devices Using WebSphere Micro Environment
This aim of this article is give an introduction to developing J2ME applications and games for Palm handheld devices. It is assumed you have some knowledge and experience with developing wireless applications/games using J2ME. The focus will be towards using J9 otherwise known as the WebSphere Mirco Environment (WME). The WME is a runtime platform compliant with J2ME provided by IBM. It comes in 2 flavors, the earlier release supports MIDP 1.0 and CLDC 1.0 and the latest release supports MIDP 2.0 and CLDC 1.1. In both cases they are targeted towards the Palm OS version 5+. Devices capable of using the MIDP 2.0 release are: * Treo 600 smartphones * Tungsten C * Tungsten T3 * Tungsten T2 * Tungsten E * Tungsten W * Zire 72 * Zire 71 Devices capable of using the MIDP 1.0 release are: * Tungsten C * Tungsten T3 * Tungsten E * Tungsten W * Zire 72 * Zire 71 For older Palm devices you may want to consider using Midp4Palm released by Sun MicroSystems; however, this platform release only supports PalmOS 3.5 and up. But given that fact that most new Palm handsets are running on 3.5 and up it should be fine. For more information about Midp4Palm visit the Sun site http://java.sun.com/products/midp4palm/ . For more information on Midp4Palm you may be interested in reading the following article "MIDP for Palm OS 1.0: Developing Java Applications for Palm OS Devices" written by Qusay Mahmoud. The WME not only supports Palm but also other PDA devices such as the Zaurus and iPAQ. WME itself really only provides the means of converting an existing MIDlet to the appropriate platform supported files in this case PRC format. If you are interested in looking for IDE IBM supplies a commercial IDE called WebSphere Studio Device Developer, a trial version is available. Otherwise you can stick with using the Wireless Toolkit by Sun and convert your application with the WME toolkit. WME/J9 Vs Midp4Palm The main differences between WME and Midp4Palm are: Midp4Palm * MIDP 1.0 and CLDC 1.0 * 64KB Limit * Midlets need to be converted to PRC format WME/9 * Latest release supports MIDP 2.0 and CLDC 1.1 * Memory limit dependant on the device limitations itself * Supports both PRC format and native JAR/JAD combination * Application Management Software (AMS) allows one to easily download, install, update, launch, set permissions and delete MIDlet suites on the Palm handset
To Keep in Mind
When developing for Palm devices you should keep in mind the following * Stylus / Pen because stylus is the main user input device it is highly recommended you adjust your application to support stylus, all Palm users are definitely use to using this. * Keyboard - remember some Palm devices have full keyboards and others only have a soft keyboard * Command Buttons The command buttons generally at the button of the screen and on the drop down menu. If the button of the screen runs out the last button contains 3 dots indicating that buttons can scroll horizontally. Command.BACK, Command.EXIT and Command.CANCEL appear in the "Navigate" menu. * Screen Size screen size and color depth vary from Palm device to Palm device * Heap and Memory Memory varies as well from Palm device to Palm device * Can't access palm native databases or any native application information though soon if not already some devices may have the JSR 75 (PDA optional package for J2ME) bundle that allows both File and PIM access. * Remember if a user invokes another application the current application gets terminated. An instance where you would need consider this is if you decide to invoke the browser by calling the MIDlet.platformRequest(URL) method. * Some PalmOS versions require the use of NetLib calls instead straight HTTP * Though J9 MIDP 2 supports JAR/JAD installation via OTA with the use of the AMS most Palm users are probably more familiar with the file format PRC and doing installations via USB cable. OTA can be achieved with PRC as well by simply pointing to the URL where PRC file resides * Refer and adhere to the WSPD license.txt file that comes with WME Toolkit, you will definitely need to think of how the end-user will get the Java run-time on to their device * To help improve and automate builds you may want to look into using Antenna and Ant * Even though you can create huge programs beyond the 64KB limit some operator gateways may disallow large downloads into the device.
Where to get it
The WebSphere Micro Environment Toolkit is available at the PalmOne developer portal. Membership is required but its free. You will find source code examples, guides and simulators at the website as well. http://www.palmone.com/us/developers/ Converting your first MIDlet to PRC Well let us get right to it, aside from taking in the considerations list above developing for the Palm is more or less the same as any other MIDlet you would make. Let us use the ole HelloWorld example, except with the added feature if you press the game keys or use the pointer (your mouse with the simulator) it will paint the appropriate message on the canvas.
Source Code:
import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class HelloWorldJ9 extends MIDlet { private Display display; private HelloWorldCanvas helloWorldCanvas; public HelloWorldJ9() { display = Display.getDisplay(this); } public void startApp() { try { this.helloWorldCanvas = new HelloWorldCanvas(this); display.setCurrent(this.helloWorldCanvas); } catch (Exception ex) { System.out.println("error: " + ex); } } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void exitApp() { destroyApp(false); notifyDestroyed(); } } Source for HelloWorldCanvas.java: import javax.microedition.lcdui.*; import java.util.*; public class HelloWorldCanvas extends Canvas implements CommandListener { private Command exitCommand = new Command("Exit", Command.BACK,1); private HelloWorldJ9 midlet; private String keyPressed = "nothing pressed"; public HelloWorldCanvas(HelloWorldJ9 midlet) throws Exception { this.midlet = midlet; addCommand(exitCommand); setCommandListener(this); } protected void pointerDragged (int x, int y) { keyPressed = "pointerDragged"; repaint(); } protected void pointerPressed (int x, int y) { keyPressed = "pointerPressed"; repaint(); } protected void pointerReleased(int x, int y) { keyPressed = "pointerReleased"; repaint(); } public void keyPressed(int keyCode) { switch(getGameAction(keyCode)) { case Canvas.FIRE: keyPressed = "Fire"; repaint(); break; case Canvas.UP: keyPressed = "Up"; repaint(); break; case Canvas.DOWN: keyPressed = "Down"; repaint(); break; case Canvas.RIGHT: keyPressed = "Right"; repaint(); break; case Canvas.LEFT: keyPressed = "Left"; repaint(); break; }; } public void commandAction(Command c, Displayable d) { if (c == exitCommand) { midlet.exitApp(); } } public void paint(Graphics g) { g.setColor(0x00FFFFFF); g.fillRect(0,0,getWidth(),getHeight()); g.setColor(0x000000FF); g.drawString(keyPressed,10,10,Graphics.TOP|Graphics.LEFT); } } Create your project, compile and package the above source code using the Wireless Toolkit from Sun. Afterwards invoke the jartoprc_w.exe in the bin directory of the WME installed home directory. Your should see the following:

Fill in the appropriate information and press "Generate PRC" you should see a PRC file where your JAD/JAR file are. For the bare minimum all you need to do is fill in the JAD and JAR location, Application Name and Version Number will automatically be populated with the information contained in the JAD file. You can leave the Icon and Splash attributes empty for now. As well you can leave the creator ID empty for now too but you will need a proper creator ID for production deployment. Now for the simulator, the PalmOne developer portal has several simulators to choose from, in this example we are going to use "Treo 600 Simulator - GSM T-MOBILE Debug" simulator. Before we can launch our HelloWorld application we need to enable the simulator with J9. From the J9 installation directory (prc/IA32) load all the PRC files drag and dropping them into the simulator. As well copy the J9JavaVMMidpNG.dll file to the main directory of the simulator. Now you can drag and drop the HelloWorld.prc file into the simulator as well. In the "Unfiled" section of the Palm interface you should see both the HelloWorld and MIDLet HQ.

The MIDlet HQ is the AMS, you can play around with that own your own. Now click on the HelloWorld. You should see simply canvas with the words nothing pressed, this will change accordingly if you press any of the game keys, on the Treo it would be the arrow keys and the center key for fire. As well if you use the stylus (mouse) you will see the corresponding action written on the canvas. If decide to deploy the application to an actual device you will need to install the following file J9JavaVMMidpNG.prc from the prc/ARM directory where WME is installed. Afterwards install your application in this case the HelloWorld.prc file. You can do this 3 ways, the first is to use HotSync program and USB/Serial connection. You can use the AMS/MIDlet HQ and install via OTA but the file format must be in JAD/JAR. The third option is to use the native browser and point it to the HelloWorld.prc file installed on a server some where. That's about it, now you know enough to get you started on developing J2ME applications and games.

Other Java Platforms for Palm
Aside from J9/WME and Midp4Palm there are other platforms for the Palm some of which or no longer being support but maybe still helpful to you especially in cases were existing applications using these platforms need to be ported over to the standard MIDP/CLDC. * Waba - www.wabasoft.com * Super Waba - www.superwaba.com.br/en/default.asp * Spotlet http:// research.sun.com/techrep/1999/smli_tr-99-73.pdf * Personal Basis Profile * JBed
* PalmOne Developer site - http://www.palmone.com/us/developers/ * MIDP for Palm by Sun - http://java.sun.com/products/midp4palm/ * WebSphere Studio Device Developer - http://www-306.ibm.com/software/wireless/wsdd/ * AMS implementation on Palm - http://www-106.ibm.com/developerworks/wireless/library/wi-amspalm/ * MIDP for Palm OS 1.0: Developing Java Applications for Palm OS Devices - http://developers.sun.com/techtopics/mobility/midp/articles/palm/ * Program your Palm in Java: The PalmOS Emulator - http://www.javaworld.com/javaworld/jw-11-1999/jw-11-device.html * palmOne Development with WebSphere Studio Device Developer Developing your first MIDlet for a palmOne device using IBM's mobile development offering * palmOne MIDP 2.0 Porting Guide Learn the specifics about WebSphere Micro Environment's support of the J2ME Mobile Information Device Profile 2.0 Specification * PalmOne Java Developer Day presentation The complete presentation slide deck from a recent developer event held by palmOne