This tutorial is the second in series designed to get developers started with MIDP and CDC development. It is strongly recommended that you complete the Java ME MIDP Quick Start Guide before beginning this tutorial. We continue building on the "MyHello" project completed in the MIDP Quick Start and show you how to deploy it to different emulators and customize the code for specific device environments. Note that the concepts and methods demonstrated in this tutorial can also be applied to CDC applications created in the IDE.
To complete this tutorial, you need the following software and resources:
Emulator platforms are provided by mobile phone manufacturers so that developers can simulate the behavior of specific mobile devices to help debug the applications they create. NetBeans IDE Mobility includes the Sun Java Wireless Toolkit, and supports many other software development kits (SDKs) that you can download from vendor sites such as Nokia, Sony Ericsson, and Motorola. You can check the NetBeans Mobility FAQ for a list of supported MIDP emulators that includes download links.
QwertyDevice emulator.You can use configurations to create more than one set of distribution JAR and Java Application Descriptor (JAD) files for your project. This enables you to create one set of source code and customize it for each mobile device you're programming for.
BlackWhiteDisplay and click OK. You have just created a new configuration. Configurations can also be added by clicking the Manage Configurations button in the Properties dialog. This brings up the Project Configuration Manager dialog which contains options for adding, removing, or duplicating configurations.You can create different types of project configurations using the templates in the New Project wizard. You can also use the drop-down Configuration menu in the main toolbar to quickly change project configurations.
You can add as many configurations as you would like to your project. You can then modify settings in the Project Properties dialog for each configuration that you've added.
BlackWhiteDisplay configuration from the configuration combo box at the top of the Properties dialog. The components in the Platform dialog are all disabled. This is because this configuration is currently taking the values used by the default configuration for this panel. Uncheck the Use Values from "DefaultConfiguration" option at the top of the panel. All components on this panel can now be edited. Change the Device option to DefaultGrayPhone. Toggle the Project Configuration dialog at the top of the Properties dialog and observe that the Device option changes based on which configuration is currently selected. This method of configuration customization works for each panel (other than the general panel) in the dialog. Click OK to save your configuration changes and exit the Properties dialog.An Ability is a specific attribute of a project configuration. It can be a physical attribute such as screen size, or an API or JSR supported by the configuration. You can create a new ability and associate it with one or more project configurations. You can then use preprocessior code blocks to associate certain code with that ability. If you later need to add or remove configurations, you do not have to go through all your code and associate the configuration with each code block. Instead, you need only to add that ability to the configuration. The configuration is then automatically associated with any code block associated with that ability.
You can associate the ability with other configurations by choosing a different configuration from the Project Configuration menu and clicking the Add button.
Preprocessor blocks enable you to create, manage and track code that is specific to one or more project configurations or abilities. The code is enabled (or disabled) only for the configurations or abilities you identify.
helloTextBox = new javax.microedition.lcdui.TextBox(null, "Make my day",120, 0x0);). Right-click on the line and choose Preprocessor Blocks > Create If/Else Block. In the first, pink section, append the word "Color" to the "Hello World" string. In the second, gray section, add "Gray" to the "Make my day " string. The code marked by the //#if preprocessor directive is in effect whenever the active configuration matches the directive value (in this case, DefaultConfiguration.) The code encased by the //#else preprocessor directive is used whenever the active configuration does not match the value of the preprocessor. In other words, the emulator displays "Make my day Color" whenever the active platform is "DefaultConfiguration," and displays "Hello World Gray" if the active platform is any other emulator platform. The //#endif preprocessor directive completes the preprocessor block.
You can test the preprocessor code by running the MIDlet using different emulator devices, as described in Changing the Emulator Platform.
Configurations can be built and run individually or simultaneously.
So far we've created a simple application, launched it on multiple emulators and added code customization to ensure that it deploys properly on multiple devices. The next step in getting started with MIDP and CLDC development is learning additional techniques for resolving device fragmentation issues.
You are viewing a mobilized version of this site...
View original page here