J2ME: First App, RSE and DSDP-MTJ

Continuing on from the day before, I started looking into specifically making an application that would run on my cell phone. At this point and time, the J2ME runtime and the associated tools seem like the best bet to get started. It’s not actually called J2ME, but rather the Sun Java Wireless Toolkit 2.5 beta, in any case some really useful development tools are packaged inside to make the mindless setup a lot easier.

To make a simple test application, start the KToolbar. I had a problem getting this to start, but that was only because KToolbar.bat was pointing to a JVM that didn’t exist anymore (I’m using the 1.5.0 8 JDK). Click ‘New Project’ and enter a project name and class name – for the sake of argument put TestProj and TestApp. Click OK, and the settings for the project are automatically loaded in a window. Check to make sure you are set up for the device you’re using, specifically the MIDP and CLDC setting are correct.

At this point KToolbar has setup the directory structure for your new application, in my case the application is inside of the apps directory of SJWT i.e. C:\WTK25\apps\TestProj. The IDE I’ll use is Eclipse, I also installed the plug-in my team here at IBM developed called RSE (Remote Systems Explorer). It can be downloaded from the Eclipse website within the DSDP Project. RSE allows you to work with remote or local devices. In this case, we can browse the file system and work with the new directory structure KToolbar made for us. (You don’t need to use Eclipse; any editor would be just fine.)

In the /src directory of TestProj create a new file called TestApp.java, the code follows:

Code:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;

public class TestApp extends MIDlet implements CommandListener {
	public void startApp() {
		Display display = Display.getDisplay(this);
		Form mainForm = new Form("TestApp");
		mainForm.append("Your first App");
		Command exitCommand = new Command("Exit", Command.EXIT, 0);
		mainForm.addCommand(exitCommand);
		mainForm.setCommandListener(this);
		display.setCurrent(mainForm);
	}

	public void pauseApp() { }

	public void destroyApp(boolean unconditional) { }

	public void commandAction(Command c, Displayable s) {
		if (c.getCommandType() == Command.EXIT) {
			notifyDestroyed();
		}
	}
}

Click here to download the code.

This is the equivalent to a Hello World program for a cell phone. Ok, so let’s review what we have so far. In the /TestProj directory there is a project.properties file, which holds the standards you are programming with, part of mine is below:

….
JSR75: false
MMAPI: true
SATSA-APDU: false
SATSA-CRYPTO: false
SATSA-JCRMI: false
SATSA-PKI: false
WMA0: false
WMA1.1: true
WMA2.0: false
….

In the /bin directory there are 2 files. The first is the manifest file holding a few project specific properties, i.e.:

MIDlet-1: TestProj, TestProj.png, TestApp
MIDlet-Name: TestProj
MIDlet-Vendor: Unknown
MIDlet-Version: 1.0
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-2.0

The second file in the /bin directory is the JAD (Java Application Descriptor) file. As defined on the Motorola Hackers Guide:

This file contains a predefined set of attributes (denoted by names that begin with “MIDlet-”) that allow application management software to identify, retrieve, and install the MIDlets. All attributes appearing in the JAD file are made available to the MIDlets. The user may define application-specific attributes and add them to the JAD file.

With the source file saved, you’re ready to build your application. From within KToolbar click the Build button and then the Run button. The source will be compiled and the toolkit will launch the Sun emulator.

On an intersting note, RSE is part of the Target Managment subproject of the Eclipse DSDP (Device Software Development Platform) project. Another subproject in DSDP is called MTJ or Mobile Tools for the Java Platform. As it turns out, Nokia is heavily involved in DSDP, specifically MTJ. Here is a quote from the press release:

Nokia and the Eclipse Foundation today announced that Nokia has joined the Eclipse Foundation as a Strategic Developer and Board member. Nokia will support the work of the Eclipse open source community by contributing software and developers to a proposed new Eclipse project.

MTJ was supposed to have had it first release by now, but its been postponed till sometime in September. I’m excited to see what their working on, I hope MTJ will support or use RSE in someway. I look forward to a day were a great open source IDE for resource constrained devices will exist. Here is a particularly interesting quote from the MTJ project page:

The purpose is to develop both frameworks that can be extended by tool vendors and tools that can be used by 3rd party mobile java application developer.

Related Articles:

Have a second? Check out this great Canadian Health & Living Store based in Toronto

Leave a Reply

Line and paragraph breaks automatic.
XHTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>