Download and install the latest Java™ SE Development Kit (JDK). The JDK is required for compiling Java classes. The NetBeans installation Guide asks you to browse to the JDK location on the local drive during installation.
Note: When installing NetBeans, select to customize the installation and clear the Features on Demand option. Download and install a software development kit (SDK) that supports Java ME. The SDK provides Java ME class libraries that the IDE requires for building MIDlets for a particular device platform.
To create MIDlets for Series 40 devices, use a Nokia SDK for Java. If you are creating MIDlets for Series 40, 6th edition, or earlier Series 40 devices, use the corresponding Series 40 SDK.
Note: To ensure that the SDK is properly integrated with the IDE, install the SDK on the same logical drive as the IDE.
To configure NetBeans:
After installing the required software, integrate NetBeans with the installed SDK:
Open NetBeans.
Select Tools > Java Platforms.
Click Add Platform.
Select Java ME CLDC Platform Emulator and click Next. NetBeans searches your computer for SDKs that support Java ME.
Figure: Selecting the Java platform type
If NetBeans does not find the SDK, click Find More Java ME Platform Folders and select the folder where you installed the SDK. NetBeans searches the selected folder for SDKs that support Java ME.
Select the SDK and click Next. NetBeans detects the SDK capabilities.
Figure: Adding a Series 40 SDK
To complete the configuration, click Finish and then Close.
Your development environment is now set and you can create the MIDlet in NetBeans.
To create the HelloWorld MIDlet:
Download and install NetBeans (select an installation bundle that supports Java ME).
Select File > New Project.
Select Java ME > Mobile Application and click Next.
In the Project Name field, enter "HelloWorld".
Figure: Creating your first MIDlet in NetBeans
Clear the checkbox Create Default Package and Main Executable Class.
Click Next. The MIDlet setup continues with device platform selection.
In the Emulator Platform drop-down menu, select the device platform for which you want to create the MIDlet:
For Series 40 devices, select a Nokia SDK for Java.
Figure: Choosing the device platform for the MIDlet
Select CLDC-1.1 and MIDP-2.1.
Click Finish. NetBeans sets up the MIDlet project.
To create the main class for the MIDlet, select File > New File.
Select CLDC > MIDlet and click Next.
In the MIDlet Name field, enter "HelloWorld".
In the MIDP Class 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 File.
Select Java > Java Class and click Next..
In the Class 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 Projects pane, right-click HelloWorld and select Deploy.
NetBeans builds the MIDlet and creates the JAR and JAD files used for deploying the MIDlet to a device. You can find the files in the Files pane under the dist folder.
Figure: HelloWorld project viewed in the Projects pane
The MIDlet is created. You can now deploy it to a device.