Friday, October 12, 2007

Your First MIDlet

As I've said in the Getting Started tutorial, we will be using NetBeans IDE in making our applications for Java enabled mobile phones. If you prefer using the J2me Toolkit you can skip this tutorial as it's a bit about familiarizing the user with the NetBeans IDE.

In this tutorial we will be creating our first, traditional "Hello World" MIDlet. "So what's a MIDlet?", you say. Bah! Details...details. Who cares, right? Seriously, in simple terms a MIDlet is a java program you can run on mobile devices such as java enabled cellphones. A MIDlet is to your phone as an exe is to pc (excuse the bad analogy heh).

If you haven't already, open the NetBeans IDE. You should see something similar to this:

Netbeans IDE

Choose "File" from the main menu and click on "New Project". Select "Mobile" from the list of Categories and "Mobile Application" from the list of Projects. Click on the "Next" button.

Choose Project

On the next screen, you get to name your project and choose it's location on your hard drive. As an example I typed "MyMidlet" in that box. Be sure to place a check on both "Set as Main Project" and "Create Hello MIDlet" options before you hit the "Next " button.

Name and Location

Select an emulator platform. I recommend choosing the one with the highest version. Leave the Device on "Default ColorPhone". Choose CLDC-1.0 from Device Configuration and MIDP 2.0 for the Device Profile. There's more about these settings later but for now hit the "Finish" button.

Default Platform Selection

If all went well, NetBeans would have created the MIDlet for you including the whole "Hello World" program. You can view the source code of the application by expanding the items of the treeview in the Projects panel. Click on the Run icon from the toolbar, it's the one with the yellow and green rectangles (back-to-backarrows?), or you can just press F6 from your keyboard.

Generated Code

After it has finished compiling and building the program the emulator window will pop-up. You will see the list of MIDlets on the phone screen with your one and only MIDlet already highlighted. You can click on the Select button or the Softkey labeled with "Launch" to run the program or you can simply hit the Enter key from your keyboard.

Running Emulator

Painless, wasn't it? Now about those "Platform Settings" we chose earlier. It really depends on the phone you want your program to run on. Most phones at the time of writing already supports MIDP 2.0 and this in turn allows us to use new libraries that were added to J2me specifically for game development. From here on, the rest of the tutorials you will find here will be focused on MIDP 2.0 phones.

The reason that I chose CLDC-1.0 is for compatibility. If you're targeting a specific phone model it's best to view the device specification for that phone from the manufacturers website. One of the main changes from CLDC-1.0 and CLDC-1.1 is that in the latter they have added support for real numbers or floats. Unless you really need to use floats in your code I suggest sticking to CLDC-1.0 for the time being. You can also find resources on the internet on how to deal with floats on the CLDC-1.0 platform.


Amit Saha said...

My name is Amit Kumar Saha and I'm the NetBeans Community Docs
Contribution Coordinator. Your blog entry would make a fantastic
tutorial for our Community Docs wiki
( Would you be willing to contribute it? If you need any help or have any questions, please contact me at I look forward to hearing from you.

Unknown said...

This is the place to be if you want to learn j2me and MIDP development. Nothing can compare. Cool Beans mann!!!

devlin said...

Thanks :)

Sleky said...

You are a life saver, I having been looking for a website for beginners to help me create a mobile phone game for my project, as i was abt giving up, i stumbled on your blog. Thank you!!!!!!!!!!!!
Abt to explore the tutorials, looks structured and easy enough to follow through.

Kim Ye-jun said...

this is so nice

Lee said...


I have been trying to run this project but the "emulator" window doesn't open. It starts the "Java ME SDK 3.0 Device Manager" but that is all.

I am using windows vista and have downloaded all the correct packages. Any idea why this has happened or how I could fix it?


Unknown said...

The King Casino Archives - Hertzaman
The King Casino Archives, including 도레미시디 출장샵 news, articles, videos, address, gaming info, The King Casino dental implants & Hotel in Henderson, NV is one of the newest hotels and motels on