Download and install the latest 32–bit version of Java™ SE Development Kit (JDK). The IDE is bundled with the latest Nokia Asha SDK 1.2 .
When you launch the IDE for the first time, you must define the workspace directory.
The HelloWorld MIDlet consists of two classes: HelloWorldMIDlet, which is the main class and defines the basic functionality of the MIDlet, and HelloScreen, which defines the HelloScreen object used by the main class to display the text "HelloWorld!" on the device screen. In the Series 40 full touch version of the MIDlet, the HelloScreen class is also used to detect display orientation changes and adjust the MIDlet UI accordingly.
To create the HelloWorld MIDlet:
Download and install Nokia Asha SDK 1.2 .
From the Start menu, select Nokia Asha SDK > Nokia Asha SDK 1.2 > Nokia IDE for Java ME (Eclipse) v3.1. The Workspace Launcher window appears.
Figure: Selecting the workspace
To use the default workspace, click OK. You can define your own workspace by editing the folder path, for example, C:\Nokia\NokiaDevEnv\HelloWorldWorkspace.
Select File > New > MIDlet Project.
If you do not see MIDlet Project listed in the menu, select File > New > Other > Java ME > MIDlet Project, and click Next.
Create a HelloWorld MIDlet, by performing the following steps:
In the Project name field, enter HelloWorld.
Figure: Creating a MIDlet project
Define the device(s) on which you want HelloWorld MIDlet to run on, by selecting the device platform in the Configurations pane and click Next. For example, Nokia Asha SDK 1.2 . To manage device platforms, use Device SDK Selector.
Figure: Selecting SDK for the MIDlet project
If you are uncertain as to which SDK you need to download, select your device from the Select Device drop-down list at the top of the window. This displays the relevant SDK to your device at the lower pane of the window. If the SDK for the platform of your choice is already installed on your local machine, select the check box next to it and select the Add button. Otherwise, select the Installed button next to the SDK you want to install.
In the MIDlet Name field, enter "HelloWorld".
In the MIDlet Vendor field, enter your name and leave MIDlet Version as is.
In the Microedition Configuration drop-down menu, select Connected Limited Device Configuration (1.1).
In the Microedition Profile list, select Mobile Information Device Profile (2.1).
Click Finish. Nokia IDE sets up the MIDlet project.
If you still see the Welcome page at this point, close it to view the HelloWorld MIDlet project.
Figure: Configuring the MIDlet project
If prompted, click Yes to open the Java ME perspective.
Now we are ready to implement the HelloWorld MIDlet. First create the HelloWorld main class for the MIDlet, by selecting File > New > Java ME MIDlet.
In the Source folder field, make sure that the value reads "HelloWorld/src".
In the Name field, enter "HelloWorldMIDlet".
Click Finish. The HelloWorldMIDlet class is created in the default package.
Figure: Creating the MIDlet main class
Delete the contents of the HelloWorldMIDlet class and paste in the following source code:
import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.midlet.MIDlet; public class HelloWorldMIDlet extends MIDlet { public HelloWorldMIDlet() { } // Sets the MIDlet's current Display to a HelloScreen object. public void startApp() { Displayable current = Display.getDisplay(this).getCurrent(); if (current == null) { HelloScreen helloScreen = new HelloScreen(this, "Hello, world!"); Display.getDisplay(this).setCurrent(helloScreen); } } public void pauseApp() { } public void destroyApp(boolean unconditional) { } }
To create the HelloScreen class, select File > New > Class.
In the Source folder field, make sure that the value reads "HelloWorld/src".
In the Name field, enter "HelloScreen".
Click Finish. The HelloScreen class is created in the default package.
Figure: Creating the HelloScreen class
Delete the contents of the HelloScreen class and paste in the following source code:
import javax.microedition.lcdui.*; class HelloScreen extends Form implements CommandListener { private final HelloWorldMIDlet midlet; private final Command exitCommand; // Exit command for closing the MIDlet in the device UI. public HelloScreen(HelloWorldMIDlet midlet, String string) { super(""); StringItem helloText = new StringItem("", string); super.append(helloText); this.midlet = midlet; exitCommand = new Command("Exit", Command.EXIT, 1); addCommand(exitCommand); setCommandListener(this); } public void commandAction(Command command, Displayable displayable) { if (command == exitCommand) { midlet.notifyDestroyed(); } } }
To use the Series 40 full touch version of the HelloScreen class, see the source code.
Now the code for the HelloWorld MIDlet is ready, click File > Save All to save the project files.
Now we must compile and make HelloWorld binaries for the device. In the Package Explorer pane, right-click HelloWorld and select Export.
In the Export window, select Java ME > Export MIDlet Package and click Next.
Figure: Export window
If the MIDlet configuration includes multiple device platforms, check the platform for which you want to package the MIDlet.
In the Destination Directory pane, check Use deployment directory. This instructs Nokia IDE to create the deployable MIDlet packages in the default deployment folder under the project folder.
You can only use a folder that already exists.
If you want to use a different folder than the default folder, enter the path of the folder in the Directory field, or click Browse and select the folder.
You can only use a folder that already exists.
Figure: Exporting the MIDlet to the default deployment folder
Click Finish.
Nokia IDE builds the MIDlet and creates the JAR and JAD files used for deploying the MIDlet to a device. If you have selected the default deployment folder, you can find the files in the Package Explorer pane under the corresponding folder.
Figure: HelloWorld project viewed in the Package Explorer pane
Note: If you need to compile your code in an existing project in a different device Emulator or platform you can go back to the Device SDK Manager by clicking on the Package Explorer Application Descriptor folder.
The MIDlet has been created. You can now deploy it to a device.