C H A P T E R  2

Introduction to the Currency Converter

This tutorial guides you through the construction of two J2ME platform, MIDP/CLDC applications:

This chapter describes the structure and function of the simple application, and shows you how to quickly install, compile, and run the Currency Converter application on a device emulator.

This chapter is organized under the following topics:

Description of the Currency Converter Application

The currency converter application, called Currency Converter, converts amounts from one currency to two others. You can choose to display three different currencies, euros, yen, or dollars, and enter a value in one currency to be converted into the other selected currencies. There are three Java source code files for the sample application:

These files, which comprise the MIDlet, are packaged with a Java Application Descriptor (JAD) file and Jar Manifest file into a MIDlet suite. MIDlet suites, along with other key concepts, are explained in Chapter 3.

Installing the Currency Converter Application

The Java Studio Mobility IDE provides an Examples Setup wizard that installs the complete example in the IDE.

Note - As with all future instructions, it is assumed the Java Studio Mobility IDE is up and running on your desktop.

To install the Currency Converter:

1. Choose Help right arrow Examples Setup Wizard.

The Examples Setup wizard opens.

 [ D ] 

2. On the Examples Setup page, check the Currency Converter Application box. Click Next.

The installation page opens, with a progress bar that indicates when the example is installed.

3. Click Finish to close the Example Setup wizard.

The Currency Converter application is installed and mounted in the default examples filesystem. You can see the directory in the Filesystems window.

Screenshot showing the Currency Converter application mounted in the Explorer window. 

Compiling and Running the Application

Now that you have installed the application, the next section shows you how to compile and run the application in a device emulator.

1. In the Filesystems window, expand the Currency Converter Application: /src filesystem node.

A Converter folder and Converter MIDlet suite node are displayed.

Screenshot of Explorer window menu tree with converter folder and converter MIDlet suite nodes visible.  

2. Right-click on the MIDlet suite and choose Execute.

The Execute function compiles the MIDlet application, if necessary, before it executes the application.

Notice that the MIDlet suite's ConverterMIDlet application runs on the emulator device skin that is configured as the default. In this case, the default is the DefaultColorPhone skin within the J2ME Wireless Toolkit 2.1 installation.

Screenshot of the DefaultColorPhone device emulator, with Currency Converter application displayed in the device.A callout points to the position of the Launch button. 

Now you're ready to test the application in the device emulator.

3. Select the currency you want to convert by clicking the up and down arrow keys on the Select button.

You can select Dollars, Euros, or Yen.

4. Enter the currency amount to convert by clicking the emulator's numeric keys.

The application makes the conversion calculations and displays the results.

5. Click the button underneath the word "Exit" to exit the application.

6. Click the red button in the upper right corner to close the emulator.

 [ D ] 

Switching Emulators

You can change the target emulator and device "skin" for a MIDlet suite, to test the performance and appearance of your MIDlet on different devices.

To switch Emulators:

1. Click the dropdown menu in the toolbar.

You can select from any of the currently installed emulators. The menu displays the default devices that are set for each of the installed emulators.

Screenshot of emulator dropdown menu, showing all avilable emulators. 

2. Select an alternate device skin. For a dramatic difference, try the RIMJavaHandheld [WTK 1.0.4] device or the QwertyDevice [WTK 2.1] device.

3. Right-click on the Converter MIDlet suite and choose Execute.

Notice that this time the application is executed with a different emulator.

4. Test the application as described in Compiling and Running the Application.

Notice that in the QwertyDevice skin shown below, the emulator has a distinctly different appearance. However, the application performance is exactly the same on both device emulators.

 [ D ] 


In this chapter, you went through the few steps it takes to compile and run a simple MIDlet in an emulator device, and how to switch emulator devices.

The next chapter will explain some MIDP concepts and prepare you to write this application using the features of the Java Studio Mobility IDE.