Monday, February 20, 2012

Creating an SMS Composer Application in NetBeans IDE 6.8 tutorial.

To  this tutorial, you need the software and resources listed below.
Software or Resource Version Required
NetBeans IDE with Java ME Version 6.9 and later
Java Development Kit (JDK) Version 6 and version 7

Installing and Running the Sample Application

Before we begin, you might want to see final result of the tutorial.
Take the following steps to install the SMSComposerExample application:
  1. Download
  2. Unzip the file.
  3. In the IDE, choose File > Open Project and browse to the folder that contains the unzipped files with the SMSComposerExample project.
  4. Click Open Project.
    The Projects window should look like the following:
    Projects window with SMS Composer example opened
  5. In the Projects window, right-click the project node and choose Run Project (or press F6).
    As the application runs, an emulator window opens and displays the application running in the default device emulator.
  6. In the Emulator window, click the button underneath "Launch". The emulator displays a Splash Screen component then SMS Composer, as shown:
    WTK 2.5 emulator displaying the sampel SMS Composer application
  • Move the cursor up and down to navigate through available options like Phone Number or Message.
  • Click the central button to enable the selected text field for editing.
  • Click the button underneath "Send" to send the message.
  • Click the button underneath "Exit" to close the application.

Creating an Application with the SMS Composer Custom Component

Now that you have seen the SMS Composer component in action, let's go back to the beginning and create this application. To create the application, do the following:
  1. Create the SMSComposerExample project
  2. Add Packages and a Visual MIDlet to the Project
  3. Add Components to the Project
  4. Add Commands to the Project
  5. Connect the Components to Create an Application Flow
  6. Modify Task for Wait Screen
  7. Run the Project

Creating the SMSComposerExample Project

  1. Choose File > New Project (Ctrl-Shift-N). Under Categories, select JavaME. Under Projects, select Mobile Application and click Next.
  2. Enter SMSComposerExample in the Project Name field. Change the Project Location to a directory on your system. From now on let's refer to this directory as $PROJECTHOME.
  3. Uncheck the Create Hello MIDlet checkbox. Click Next.
  4. Leave the Sun Java Wireless Toolkit as the selected Emulator Platform. Click Next.
  5. Click Finish.
  6. Note: The project folder contains all of your sources and project metadata, such as the project Ant script.

Adding Packages and a Visual MIDlet to the Project

  1. Choose the SMSComposerExample project in the Project Window, then choose File > New File (Ctrl-N). Under Categories, select Java. Under File Types, select Java Package. Click Next.
  2. Enter smscomposerexample in the Package Name field. Click Finish.
  3. Choose the smscomposerexample package in the Project window, then choose File > New File (Ctrl-N). Under Categories, select MIDP. Under File Types, select Visual MIDlet. Click Next.
  4. Enter SMSComposerExample into MIDlet Name and MIDP Class Name fields. Click Finish.
    The application displays in the Flow Design window of the Visual Mobile Designer.
  5. SMSComposerExample in the Visual Mobile Designer

Adding Components to the Project

  1. In the Flow Designer window, drag and drop the following components from the Component Palette:
    • Splash Screen
    • SMS Composer
    • Wait Screen
    • Alert (x2)
  2. Click on splashScreen and, in the Properties Window, change value of property Text from null to the SMS Composer Example and press Enter.
  3. Click on alert and, in the Properties Window, change value of property Title from alert to the alertSent, the same way change alert1 Title property from alert1 to the alertError.
  4. Click on alert and, in the Properties Window, change value of property String to the Message Sent, the same way change property String in the component alertError to the Error.
  5. Click on smsComposer and, in the Properties Window, uncheck the Automatically Send property in the SMS Properties category.

Adding Commands to the Project

  1. Open the Flow Designer.
  2. Choose Exit Command from the Commands section of the Component Palette. Drag and drop it into the smsComposer component in the Flow Designer.

Connecting Components to Create an Application Flow

In the Flow Designer, click on the Start Point on the Mobile Device and drag it to the spalshScreen component. In the same manner, connect the components together as shown in the following graphic.
Shows the Flow Designer with components connected by command lines

Modifying Task for Wait Screen

In the Resources category of the Navigator, find and right-click the task component, choose Go To Source from the popup menu. In the Source window, find section // write task-execution user code here" and replace it with smsComposer.sendSMS();.

Running the Project

Press to Run the main project. Alternatively you could select Run > Run Main Project.

Javadoc for the SMS Composer Component

The NetBeans IDE provides API Javadocs for the SMSComposer component, as well as other components you can use in the VMD. To read the Javadocs for the SMSComposer component:
  1. Place the cursor on the SMSComposer component in the source code and press Ctr-Shift-Space (or choose Source > Show Documentation).
    The Javadoc for this element displays in a popup window.
  2. Click the Show documentation in external web browser icon (Show documentation in external web browser) in the popup window to view the detailed information about the SMSComposer component in your browser.