Creating CLDC/MIDP applications

In this recipe we will use Mobile Information Device Profile (MIDP) as the profile for our Mobile application.

MIDP is the best-known JME profile and provides core functionality that will run across many devices, giving apps more portability.

In later recipes we will also favor MIDP since the market for those applications has exploded in recent years and it is more enticing for developers to work in.

Keep in mind that MIDP applications should be written with memory consumption and processing power constraints/limitations in mind.

Getting ready

If NetBeans is not currently installed visit the download sections on:

http://download.netbeans.org

It is possible to find the full version of NetBeans that contains Java ME; upon installation remember to select the Java ME option.

With NetBeans ready, we can start coding.

How to do it...

  1. Create a new project, this can be achieved by either clicking File and then New Project or pressing Ctrl+Shift+N.
  2. On the New Project window on Categories side choose Java ME and on the Projects side select Mobile Application, then click Next.
  3. Under Name and Location: Name the project as MyMIDPApp, leave the other options with their default values and click Next.
    How to do it...
  4. Under Default Platform Selection: On Emulator Platform select Java(TM) Platform Micro Edition SDK 3.0.
  5. Click Finish.

How it works...

The folder structure created by NetBeans for a Java ME project is rather extensive. The project is created with an Ant build file, which already includes several targets. On top of that .properties files are created for the convenience of the developer.

To have access to all of the files shown in the screenshot below it is necessary to build the project. To do this right-click on the project and select Build.

After the build step, navigate to the Files window and expand the nodes to see the properties files. They each have different roles:

  • Projects.properties: contains sets of key/values pairs that aid developers in configuring the project.
  • Genfiles.properties: used by the IDE to track the changes generated by the build.
  • Private.properties: specific to versioning and deployment of the application.

Also present is a MANIFEST file. This file is accessed by the device to show the version number and name of the application when installed in the mobile.

How it works...

NetBeans then creates the HelloMidlet.java, which is our main class for developing with Java ME. For now, this is where the entire code of our project placed.

It is possible to edit the code in different ways:

  • Source View: This is where the developer can write the code. By clicking on it the view changes to the Java Code editor, where it is possible to see the code generated by the IDE (the grayed-out and commented parts) and the user-editable content.
  • Screen View: Allows the developer to build the UI graphically by dragging and dropping components from the Palette window.
How it works...
  • Flow View: Lets the developer create and build the flow between windows and add behaviors, in the form of commands, to the components from the Palette window. This is shown in a very user-friendly and graphical way to the developer, very similar to UML diagrams.
How it works...
  • Analyzer View: Since every part of memory counts in mobile applications, this view is responsible for analyzing the code for unused components, screens, or resources that might be left on our mobile application.

To run our first Mobile Application, simply right-click on our projects node and select run.

There's more...

There is more than one way to run your project with different devices.

Deploying applications on different device models

On project creation, we can pick the device we are designing our app for and will be deploying on.

Click on the Default Platform Selection dropdown and the list will be presented.

If a project already exists we can change the target device:

  1. Right-click on the mobile project, in our case MyMIDPApp, and select Properties.
  2. Click on Platform and under Device, it is possible to check the available phones.
Deploying applications on different device models

The function of the optional packages selected in the above screenshot is to enable features in the JME application that would otherwise be not supported. For example, the ContentHandler API lets applications execute other registered applications by URL. To learn more about this specific API visit:

http://download.oracle.com/javame/config/cldc/opt-pkgs/api/ch/jsr211/index.html

For the other available APIs please refer to:

http://download.oracle.com/javame/

Alternatively, when testing, it is possible to select the device prior to running the application. Right-click on the project node and select Run With... and you will be presented with the Quick Project Run dialog:

Deploying applications on different device models

Adding more Platforms

Java comes pre-loaded in many different devices. One of the biggest deployments of Java in the mobile phone world is in Symbian phones. Symbian contains many different types, Symbian^3, S40, and so on.

We will add the SDK to work with S40 devices.

First visit:

http://www.forum.nokia.com/Library/Tools_and_Downloads/

Create an account and download the S40 fifth edition Java SDK.

Upon installation completion, go to NetBeans:

  1. Click on Tools and Java Platform.
  2. On the Java Platform Manager window, click on Add Platform.
    Adding more Platforms
  3. Under Select Platform Type: select Java ME MIDP Platform Emulator and click Next >.
  4. Under Platform Folders: Be sure that Nokia S40 platform is shown and click Next >.
    Adding more Platforms
  5. Under Detected Platforms: Select the Nokia S40 platform SDK and click Finish.
    Adding more Platforms
  6. Back on Java Platform Manager the JME available platforms will now contain the Series 40 5th Edition SDK.
  7. Click Close.
  8. Now right-click our project and click on Platforms on the right-hand side of the pane.
  9. Click on the Emulator Platform drop down and the Series 40 5th Edition Platform will be available for choosing.
Adding more Platforms
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.74.205