Download and install the latest Java™ SE Development Kit (JDK). The IDE is bundled with the latest Nokia Asha SDK 1.0.
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 IDE for Java ME (Eclipse).
Select File > New > MIDlet Project.
Tip: If you do not see MIDlet Project listed in the menu, select File > New > Other instead, select Java ME > MIDlet Project, and click Next.
In the Project name field, enter HelloWorld.
Figure: Creating a MIDlet project
Click on the Device SDK Manager button.
Figure: Selecting SDK for the MIDlet project
Note: 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 Install window, select the platform and then click Next.
Figure: Installing SDK for the MIDlet project
Click Finish and restart the IDE for changes to take effect. You can see the newly added platform under the Configurations section.
Select the platform you have added in Configurations and click Next.
In the MIDlet Name field, enter "HelloWorld".
In the MIDlet Vendor field, enter your name.
In the Microedition Configuration drop-down menu, select Connected Limited Device Configuration (1.1).
In the Microedition Profile drop-down menu, select Mobile Information Device Profile (2.1).
Click Finish. Nokia IDE sets up the MIDlet project.
Figure: Configuring the MIDlet project
If prompted, click Yes to open the Java ME perspective.
To create the main class for the MIDlet, select 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(); } } }
Tip: To use the Series 40 full touch version
of the HelloScreen
class, see the source code.
Save the project by selecting File > Save All.
In the Package Explorer pane, right-click HelloWorld and select Export.
Select Java ME > Export MIDlet Package and click Next.
If the MIDlet configuration includes multiple device platforms, check the platform for which you want to package the MIDlet.
Note: You can only use a folder that already exists.
Tip: 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.
Note: 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.