Visual Mobile Designer Custom Components: Creating an SMS Composer Application
The Visual Mobile Designer (VMD) is a graphical interface within NetBeans Mobility that enables you to design mobile applications using drag and drop components. The
VMD allows you to define the application flow and design your GUI using the components supplied by the IDE, or components you design yourself. The VMD contains many standard User Interface (UI) components that you can use to create applications such as Lists, Alerts, Forms and Images. It also includes custom components that simplify the creation of more complex features, such as Wait Screens, Splash Screens, Table Items and more.
The SMS Composer is a custom component that provides a mechanism and user interface to send short message using Short Message Service (SMS).
This component utilizes the JSR-120 Wireless Messaging API. This API is
not a part of the MIDP 2.0 specification so this custom component can only be deployed to devices that have built-in support for JSR-120.
This tutorial shows you how to use the SMS Composer component in a mobile application for Wireless Messaging API (WMA) enabled devices.
You'll learn the basic features of this component, and how to send message using Short Message Service.
In addition to the SMS Composer custom component we also need to use two other MIDP components: Splash Screen and Alert.
To follow this tutorial, you need the software and resources listed below.
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:
- Download SMSComposerExample.zip.
- Unzip the file.
- In the IDE, choose File > Open Project and browse to the folder that contains the unzipped files with the SMSComposerExample project.
- Click Open Project.
The Projects window should look like the following:
- 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.
- In the Emulator window, click the button underneath "Launch". The emulator displays a Splash Screen component then SMS Composer, as shown:
- 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:
- Create the SMSComposerExample project
- Add Packages and a Visual MIDlet to the Project
- Add Components to the Project
- Add Commands to the Project
- Connect the Components to Create an Application Flow
- Modify Task for Wait Screen
- Run the Project
Creating the SMSComposerExample Project
- Choose File > New Project (Ctrl-Shift-N). Under Categories, select JavaME. Under Projects, select Mobile Application and click Next.
in the Project Name field. Change the Project Location to a directory on your system. From now on let's refer to this
- Uncheck the Create Hello MIDlet checkbox. Click Next.
- Leave the Sun Java Wireless Toolkit as the selected Emulator Platform. Click Next.
- Click Finish.
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
- 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.
smscomposerexample in the Package Name field. Click Finish.
- 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.
SMSComposerExample into MIDlet Name and MIDP Class Name fields. Click Finish.
The application displays in the Flow Design window of the Visual Mobile Designer.
Adding Components to the Project
- In the Flow Designer window, drag and drop the following components from the Component Palette:
Click on splashScreen and, in the Properties Window, change value of property Text from null to the SMS Composer Example and press Enter.
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.
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.
Click on smsComposer and, in the Properties Window, uncheck the Automatically Send property in the SMS Properties category.
- Splash Screen
- SMS Composer
- Wait Screen
- Alert (x2)
Adding Commands to the Project
- Open the Flow Designer.
- 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.
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
Running the Project
Press <F6> 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:
- 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.
- Click the Show documentation in external web browser icon () in the popup window to view the detailed information about the SMSComposer component in your browser.