Java ME MIDP Development Quick Start Guide
This tutorial guides you through the
basic steps of using NetBeans IDE to create a Java™ Platform, Micro Edition
(Java™ ME platform), Mobile Information Device Profile (MIDP) application and
is designed to get you started with mobile application development as quickly
as possible. The tutorial takes you through some of the basic steps of working
with the project system. We show you two ways to create a Java ME MIDP project
named "MyHello" that displays the text "Make My Day" in a
device emulator. This tutorial prepares you to use other IDE features for
developing CLDC/MIDP applications.
Note: If you are using NetBeans IDE 7.3 or 7.3.1, refer to the NetBeans IDE 7.3 Java ME MIDP Development Quick Start Guide.
Contents

- Tutorial Requirements
- Setting Up the IDE with Oracle Java ME SDK (Windows only)
- Creating an Application in the Source Editor
- Creating an Application in the Visual Mobile Designer
- Next Steps
To complete this tutorial, you need
the following software and resources:
|
Software
or Resource
|
Version
Required
|
|
Version 7.4
|
|
|
Java Development Kit
(JDK)
|
Version 7
|
|
Depends on the operating system
|
Important: The table below lists versions of Oracle Java ME SDK
required for particular platforms.
|
Platform
|
SDK
Version Required
|
|
Microsoft Windows
|
|
|
Mac OS X
|
|
|
Linux
|
Important: This section applies to Windows platforms only.
To set up NetBeans IDE with the
Oracle Java ME SDK for the Windows platform, you need to:
- install Oracle Java ME SDK
- activate the Java ME feature in NetBeans IDE
- install the Oracle Java ME Platform SDK in NetBeans IDE
To install Oracle Java ME SDK:
- Go to the Java ME SDK download page.
- Click the Accept License Agreement option.
- Download the oracle-jmesdk-3-4-rr-win32-bin.exe installer file and save it to any location on your computer.
- Double-click the installer file to run the installer,
and follow the instructions.
When the installation is complete, the Java (TM) ME Platform SDK 3.4 Device Manager icon (
)
appears in the Windows system tray.
To activate the Java ME feature:
- Choose Tools > Plugins from the main IDE's toolbar.
- In the Plugins dialog box, click the Installed tab and select Java ME in the list of available features.
- Click Activate.
- At the Welcome panel of the Installer dialog box, click Activate.
- When the activation is successfully completed, click Finish.
- Click Close to close the Plugins dialog box.
To install the Oracle Java ME
Platform:
- Choose Tools > Java Platforms.
The Java Platform Manager dialog box displays.
- Click Add Platform.
- In the Select Platform Type of the Add Java Platform
wizard, select Java ME CLDC Platform Emulator and click Next.
The IDE displays the Choose directory to search for platforms dialog box. - Select the directory you installed the Java ME SDK Platform to (for example, C:\Java_ME_Platform_SDK_3.4) and click Open.
- In the Platform Folders panel of the Add Java Platform wizard, ensure the platform you selected in the previous step is chosen and click Next.
- As soon as the IDE detects the platform, click Finish in the Detected Platforms panel of the the Add Java Platform wizard.
The Oracle
Java ME Platform is now registered in the Netbeans IDE.
- In the Java Platform Manager dialog box, click Close.
Now your NetBeans IDE is set up for mobile
development.
Using the Source Code Editor, you
manually create the code for your MIDlets. Creating code in the Source Code
Editor gives you more flexibility when editing the code, and enables you to
insert preprocessor code blocks. You are going to create a MyHello application using the New Project and New File wizards, and
complete the code using the Source Editor.
Creating
a New Java ME MIDP Project
- Choose File > New Project. Under Categories, select Java ME. Under Projects, select Mobile Application and click Next.
- Enter MyHelloMIDlet in the Project Name field (note that MID is in upper case letters). Specify the Project Location. We refer to this directory as $PROJECTHOME in this tutorial.
- Deselect the Create Default Package and Main Executable Class checkbox and click Next.
- Select the default emulator platform and use the
remaining defaults. Click Finish.
The IDE creates the $PROJECTHOME/MyHelloMIDlet project folder. The project folder contains all of your sources and project metadata, such as the project Ant script. - Right-click the MyHelloMIDlet node in the Projects window and choose New > MIDlet.
- Enter HelloMIDlet as the MIDlet name (note that "MID" is not
in upper case letters by default). Click Finish.
The HelloMIDlet.java file is created. - Double-click the HelloMIDlet.java file to display the source code in the IDE's Editor window.
- Click in the Source Editor and change public class HelloMIDlet extends MIDlet to
9. public
class HelloMIDlet
10.extends
MIDlet implements javax.microedition.lcdui.CommandListener
{
- Add the following text before the startApp() method:
12. private void initialize() {
13.
javax.microedition.lcdui.Display.getDisplay(this).setCurrent(get_helloTextBox());
14. }
15.
16. public void
commandAction(javax.microedition.lcdui.Command command,
javax.microedition.lcdui.Displayable displayable) {
17. if (displayable == helloTextBox) {
18. if (command == exitCommand) {
19.
javax.microedition.lcdui.Display.getDisplay(this).setCurrent(null);
20. destroyApp(true);
21. notifyDestroyed();
22. }
23. }
24. }
25.
26. private javax.microedition.lcdui.TextBox
get_helloTextBox() {
27. if (helloTextBox == null) {
28. helloTextBox = new
javax.microedition.lcdui.TextBox(null, "Hello Test Code", 120, 0x0);
29.
helloTextBox.addCommand(get_exitCommand());
30.
helloTextBox.setCommandListener(this);
31. }
32. return helloTextBox;
33. }
34.
35. private javax.microedition.lcdui.Command
get_exitCommand() {
36. if (exitCommand == null) {
37. exitCommand = new
javax.microedition.lcdui.Command("Exit",
javax.microedition.lcdui.Command.EXIT,
38. 1);
39. }
40. return exitCommand;
41. }
42. javax.microedition.lcdui.TextBox
helloTextBox;
43. javax.microedition.lcdui.Command
exitCommand;
- Add a line initialize(); to the startApp() method, so it looks like the following:
45. public void startApp() {
46.initialize();
47.}
Editing
the Java Source Code
Now let's add some text for our
MIDlet to display.
In the get_helloTextBox() method, replace the example Hello Test Code
code with the text of your choice (for example, Make My Day.).
Note: For a complete guide to using code assistance features, customization
options, and navigation capabilities of the NetBeans IDE's Java Editor see Code Assistance in the NetBeans IDE Java Editor.
Compiling
and Running the Project
Choose Run
> Run Project
(MyHelloMIDlet) from the main IDE's toolbar. Follow
the progress of the project compilation in the Output window. Note that the HelloMIDlet.java file is built before it is executed. A device emulator opens
to display the results of the executed MIDlet and displays the text you entered
in the source code.
To close the MIDlet and the emulator
window, choose Application > Exit in the emulator window.
The NetBeans IDE provides a wizard
that enables you to quickly create a MIDP project. When creating the project,
you can choose to develop your application in the Visual Mobile Designer (VMD)
or in the Source Code Editor. Using the VMD gives you the ability to visually
plan out the flow of the application and design the screens the application
uses. The designer automatically creates the code for the application as
changes are saved on the design canvas.
Important: To run the Visual Mobile Designer in the IDE you need to
install the Visual Mobile Designer plugin from the Update Center as follows:
- Choose Tools > Plugins from the main menu.
- On the Available Plugins tab of the Plugins dialog box, select Visual Mobile Designer and click Install.
- At the Welcome page of the Installer dialog box, click Next.
- At the License Agreement page, read the license agreements associated with the plugin. If you agree to the terms of all of the license agreements, click the appropriate option and then click Install.
- (Optional) Select the Run in the Background option to run the installation in the background.
- When the installation process is complete, click Finish.
- In the Plugins dialog box, click Close.
Creating
a MIDP/CLDC Application
- Choose File > New Project (Ctrl+Shift+N). Under Categories, select Java ME. Under Projects, select Mobile Application and click Next.
- Enter MyHello in the Project Name field. Use the default Project Location, or change it to the directory you prefer on your system. In this tutorial we refer to this directory as $PROJECTHOME.
- Leave the Create Default Package and Main Executable Class check box selected. Click Next.
- Select the default as the emulator platform and use the remaining defaults. Click Finish.
- The IDE creates the $PROJECTHOME/MyHello project folder. The project folder contains all of your sources and project metadata, such as the project Ant script. The application itself is displayed in the Flow Design window of the Visual Mobile Designer.
Note: For a complete description of the available palette
components, please refer to the Visual Mobile Designer Palette Reference.
Editing
the Java Source Code
Now let's edit the text displayed by
the MIDlet.
- Under HelloMIDlet.java click Screen to switch to the Screen View displaying the Device Screen, which is the only screen available in the application.
- Click the Hello World! message in the Device Screen. In the Properties window click the Hello World! text to change the welcome message text and press Enter. In this example we typed Make my day.

- The Screen View displays a preview of the text you enter in the Text field.
Compiling
and Running the Project
- Choose Run > Run Project (MyHello) from the main IDE's toolbar. Follow the progress of the project compilation in the Output window. Note that the HelloMIDlet.java file is built before it is executed. A device emulator opens to display the results of the executed MIDlet. The device emulator launches the MIDlet and displays the text you entered in the source code.
You can
specify the emulator to run the MIDlet on by right-clicking the project node
and selecting Run With.. from the contextual menu. The JavaMEPhone1 available in Java ME SDK 3.4 is shown below.
- In the emulator window, choose Application > Exit to close the MIDlet and the emulator window.









Tidak ada komentar:
Posting Komentar