Skip Headers
Oracle® Java Micro Edition Software Development Kit Developer's Guide
Release 3.4 for Eclipse on Windows
E37550-04
  Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
 
Next
Next
 

4 Using Sample Projects

The Oracle Java ME SDK sample projects introduce you to the emulator's API features and the SDK features, tools, and utilities that support the various APIs. These features can help you customize the sample projects or create applications of your own. For instructions on creating new projects, see "Projects."


Note:

Before using the Oracle Java ME SDK demo applications, see "Installation and Runtime Security Guidelines" in Appendix A. Some demos use network access and open ports, and do not include protections against malicious intrusion. If you choose to run the sample projects, you should ensure your environment is secure.


For instructions on running projects, see the following topics:

4.1 Creating a Sample Project

Sample applications are installed in a separate Eclipse plugin. Do not run or edit these projects directly. You create a new project that is an instance of the sample project.

The default location for Oracle Java ME SDK projects is the default Eclipse project directory. Each project has a src directory that contains Java programming language source code. For example, the default location of the source code for the SMS sender MIDlet (example.sms.SMSSend) in WMADemo resides in the following location:

EclipseWorkspace\WMADemo\src\example\sms\SMSSend.java

  1. Go to File > New > Project and in the Categories window.

  2. Select Examples > Java ME SDK 3.4 and click on Java ME Sample Applications then Click Next.

    In the next screen select one of the samples and click Finish.

  3. If prompted, select an emulator platform and a device. Note, changing the device affects the possible device profiles, so you might need to explicitly select a profile. Click OK.

    The project is added to the Package Explorer window.


    Note:

    If you cannot see the Package Explorer window select Window > Show View > Package Explorer. To see console output, select Window > Show View > Console.


4.2 Running a Project

Create your own project, or instantiate one of the sample projects provided with the SDK as described in "Creating a Sample Project."

  1. Use one of these methods to run a project.

    • Select a project and click the Run button in the toolbar.

    • Right-click a project and select Run As > Emulated Java ME JAD from the context menu.

    • To run a project on a different device, or to change the execution mode, select the device in the Device Selector window (Window > Show View > Other > Java ME SDK Tools > Device Selector). Right-click on a device and select Run Project from the context menu. Pull right to see a listing of open projects.

      Figure 4-1 Running a Project on the Device Selector

      Description of Figure 4-1 follows
      Description of "Figure 4-1 Running a Project on the Device Selector"

    • To run a project on an emulator, drag and drop the project's JAD or JAR file onto a running emulator. Click OK in the Run MIDlet (or IMlet) Suite dialog box.

    The device emulator window opens with the demo application running. If the demo is a MIDlet suite you might have to select a MIDlet to launch.

  2. As the sample project runs, soft keys might be enabled below the screen on the left or right side.

    You use soft keys to install or launch an application, open a menu, exit, or perform some other action. Some demos include these instructions in the application.

    For instructions on running samples, see Table 4-1.

  3. When you are finished viewing an application, go to the emulator's Application menu and select Exit to close the emulator and stop the execution of the project's build script.

    When the emulator is launched, it runs as an independent process. Stopping the application from Eclipse does not close the emulator instance.

    Likewise, closing the Eclipse IDE does not affect the emulator instance. In the emulator, click the Application menu and select Exit or press the emulator's exit button (the X) on the upper right to ensure that both the emulator process and the project build process close.

Periodically, you might want to clear a device's database especially after you have run several projects. Right-click the device and select Clean RMS storage files. When you run the command, a completion notice is displayed in the IDE's status bar.

4.3 Troubleshooting

Sometimes even a "known good" application, such as a sample project, does not run successfully. The problem is usually your environment.

4.4 Sample Project Overview

The Oracle Java ME SDK includes demonstration applications that highlight some technologies and APIs that are supported by the emulator.

Most demonstration applications are simple to run. "Running a Project" contains instructions for running most demonstrations. Sample projects usually have some additional operation instructions.

Table 4-1 lists all the MIDP/CLDC demonstration applications that are included in this release.

Table 4-1 MIDP/CLDC Sample Projects

Sample Optional Package Description Instructions

Advanced Multimedia Supplements

JSR 234

Demonstrates 3D audio, reverberation, image processing, and camera control.

Chapter 17, "JSR 135: Mobile Media API Support"


AudioDemo

MMAPI 1.1

Demonstrates audio capabilities, including mixing and playing audio with an animation.

Chapter 17, "JSR 135: Mobile Media API Support"


BluetoothDemo

JSR 82

Demonstrates device discovery and data exchange using Bluetooth.

Chapter 16, "JSR 82: Bluetooth and OBEX Support"


CHAPIDemo

JSR 211

A content viewer that also uses MediaHandler.

Chapter 22, "JSR 211: Content Handler API (CHAPI)"


CityGuide

JSR 179

A city map that displays landmarks based on the current location.

Chapter 19, "JSR 179: Location API Support"


ContactlessDemo

JSR 257

Emulates detection of RFID tags.

Chapter 26, "JSR 257: Contactless Communication API"


Demos

MIDP 2.1

Includes various examples: animation, color, networking, finance, and others.

"Running MIDP and CLDC Sample Projects"


FPDemo

CLDC 1.1

Simple floating point calculator.

"Running MIDP and CLDC Sample Projects"


Games

MIDP 2.1

Includes TilePuzzle, WormGame, and PushPuzzle.

"Running MIDP and CLDC Sample Projects"


MMAPIDemos

MMAPI

Demonstrates MMAPI features, including tone sequences, MIDI playback, sampled audio playback, and video.

Chapter 17, "JSR 135: Mobile Media API Support"


Multimedia

MMAPI

Demonstrates different video playback formats.

Chapter 17, "JSR 135: Mobile Media API Support"


NetworkDemo

MIDP 2.1

Demonstrates how to use datagrams and serial connections.

"Running MIDP and CLDC Sample Projects"

ObexDemo

JSR 82

Demonstrates device discovery and data exchange using Bluetooth.

Chapter 16, "JSR 82: Bluetooth and OBEX Support"


PDAPDemo

JSR 75

Demonstrates how to manipulate contacts, calendar items, and to-do items. Demonstrates accessing local files.

Chapter 15, "JSR 75: PDA Optional Packages"


PhotoAlbum

MIDP 2.1

Demonstrates a variety of image formats.

"Running MIDP and CLDC Sample Projects"


SATSADemo

JSR 177

Demonstrates communication with a smart card and other features of SATSA.

Chapter 18, "JSR 177: Smart Card Security (SATSA)"


SATSAJCRMIDemo

JSR 177

Shows how to use the SATSA-Java Card Remote Invocation method.

Chapter 18, "JSR 177: Smart Card Security (SATSA)"


Sensors

JSR 256

The SensorBrowser and Marbles game demonstrate sensor input.

Chapter 25, "JSR 256: Mobile Sensor API Support"

SVGContactList

JSR 226

Uses SVG to create a contact list displayed with different skins.

Chapter 23, "JSR 226: Scalable 2D Vector Graphics"


SVGDemo

JSR 226

Uses different SVG rendering techniques.

Chapter 23, "JSR 226: Scalable 2D Vector Graphics"


UIDemo

MIDP 2.1

Showcases the breadth of MIDP 2.0's user interface capabilities.

"Running MIDP and CLDC Sample Projects"


WMADemo

WMA 2.0

Shows how to send and receive SMS, CBS, and MMS messages.

Chapter 20, "JSR 205: Wireless Messaging"


XMLAPIDemo

JSR 280

Uses DOM and STAX APIs to create an XML sample and SAX, DOM and StAX APIs to parse the sample.

Follow the instructions the application provides.


Table 4-2 IMP-NG Sample Projects

Sample Description Instructions

GPIODemo

Changes the state of LEDs in an emulator or reference platform.

"Running the GPIODemo"


I2CDemo

Writes data to a slave and then retrieves it.

"Running the I2CDemo"


NetworkDemoIMPNG

Allows connection and communication between a server and a client instance.

"Running the NetworkDemoIMPNG"


PDAPDemoIMPNG

Demonstrates management of a file system in the emulator.

"Running the PDAPDemoIMPNG"


Pulse Counter (Data Collection) Demo

Sends pulses to a counter and tracks them when they arrive using a timestamp.

"Running the Pulse Counter (Data Collection) Demo"


LightTrackerDemo

Controls LEDs on a reference platform.

"Running the Light Tracker Demo"


SystemControllerDemo

Demonstrates IMlet lifecycle on a reference platform.

"Running the System Controller Demo"



4.5 Configuring the Web Browser and Proxy Settings

If you are behind a firewall you must configure the proxy server so that MIDP applications using web services can succeed.

The settings are typically the same as those you are using in your web browser. Select Window > Preferences > General > Network Connections and change the settings as appropriate.

4.6 Running MIDP and CLDC Sample Projects

This topic gathers MIDP and CLDC samples that are not discussed in separate chapters. This is the case when a sample uses many JSRs, or when a supported JSR does not have any special implementation details.

For other CLDC demos, see Table 4-1.

4.6.1 Running the AdvancedMultimediaSupplements Sample Project

This MIDlet suite demonstrates the power of JSR 234 Advanced Multimedia Supplements (AMMS). It consists of the following MIDlets:

4.6.1.1 Image Effects

This MIDlet demonstrates standard image processing operations.

  • Launch the Image Effects MIDlet.

  • Select input and output image formats, and press Done. The input image and output images are displayed simultaneously.

  • Select an effect from the Menu and click the Done button to apply a transformation, effect or overlay. The source image is shown above and the processed image is shown below. Some items, Set Transforms, for example, can perform several operations in a single transaction.

    The menu options are as follows:

    • Reset - Set transforms, effects, and overlays to the initial state.

    • Monochrome Effects - Activate grayscale rendering.

    • Negative Effect -Reverse dark and light areas.

    • Set Formats - Select an input object type and an output image format.

    • Set Effect Order - Specify the order in which transforms, effects and overlays are applied.

    • Set Transforms - Change width and height scale, border, and rotation options.

    • Set Overlays - Specify the color and orientation of a color block overlay.

4.6.1.2 Music Effects

Demonstrates the advanced audio capabilities of the Advanced Multimedia Supplements. As an audio file loops continuously, you can adjust the volume, and reverberation settings.

4.6.1.3 Camera

This MIDlet demonstrates how the Advanced Multimedia Supplements provide control of a device's camera. The screen shows the viewfinder of the camera (simulated with a movie). You can use commands in the menu to change the camera settings and take and manage snapshots.

  • Zoom settings - digital and optical zoom settings 100-300 in increments of 20. Make a selection and press Back.

  • View gallery - View a list of the snapshots stored in: username\javame-sdk\3.4\work\devicename\appdb\filesystem\root1. Select Display to see the snapshot. You have the option to delete the file from disk. If \root1 is empty use the Snapshot option to save images for the gallery.

  • Set flash mode - Off, AUTO, AUTO_WITH_REDEYEREDUCE, FORCE, FORCE_WITH_REDEYEREDUCE, FILLIN.

  • Change F_Stop number - 0, 400, 560, 800, 1600.

  • Select exposure modes - Preset modes are auto, landscape, snow, beach, sunset, night, fireworks, portrait, backlight, spotlight, sports, text.

  • Disable/Enable shutter feedback.

  • Exit - Close this MIDlet and return to the initial window.

  • Snapshot setting - Set whether to display the snapshot on the screen or print it to a file. Snapshots are stored in:

    username\javame-sdk\3.4\work\devicename\appdb\filesystem\root1

4.6.1.4 Moving Helicopter

Simulates a helicopter (red dot) flying around a stationary observer (blue dot). Use headphones for best results. You can control the parameters of the simulation with the soft menu options: Volume, Location settings, Spectator orientation, and Distance Attenuation settings. After viewing menu options, press the close button (the X on the right) to return to the helicopter scenario.

With the Location settings be aware that supplying large values for the screen width or flight altitude means the helicopter might be out of range - that is, it flies off the screen and you might not be able to hear it.

For spectator orientation stereo headphones or speakers help detect the difference in position, assuming your volume and location settings put the helicopter in audible range. The same is true for the Distance Attenuation settings, which enable you to control the doppler effect.

4.6.2 Running the Demos Sample Project

This demo contains several MIDlets that highlight different MIDP features. Click or use the navigation keys to highlight a MIDlet, then select the Launch soft key.

4.6.2.1 Colors

This application displays a large horizontal rectangle that runs the width of the screen. Below, ten small vertical rectangles span the screen. Finally, three horizontal color bars indicate values for blue, green, and red (RGB). Values are expressed as decimal (0-255) or hexadecimal (00-ff) based on the first menu selection.

  • To select a vertical bar to change, use the up navigation arrow to move to the color bars. Use the right navigation arrow to highlight a color bar. The large rectangle becomes the color of the selected bar.

  • Use the up or down selection arrows to select the value to change (red, green, or blue). Use the left or right arrow keys to increase or decrease the selected value. The second menu item enables you to jump in increments of 4 (Fine) or 32 (coarse).

  • You can change the color on any or all of the vertical bars.

4.6.2.2 Properties

This MIDlet displays your system property values. The output is similar to the following values:

Free Memory = 2333444
Total Memory = 4194304
microedition.configuration = "CLDC-1.1"
microedition.profiles = "MIDP-2.1"
microedition.platform = "generic"
microedition.locale = "en-US"
microedition.encoding = "IS08859_1"

4.6.2.3 Http

This test application uses an HTTP connection to request a web page. The request is issued with HTTP protocol GET or POST methods. If the HEAD method is used, the head properties are read from the request.

Preparing to Run the Demo

Before beginning, examine your settings as follows.

  • Select Demos.

    • Click the Run menu and select Run Configurations.

    • Click the Emulation tab.

    • Select Maximum in the Security Domain field.

    • Click Apply.

  • If you are using a proxy server, you must configure the emulator's proxy server settings as described in "Configuring the Web Browser and Proxy Settings." The HTTP version must be 1.1.

  • If you are running antivirus software it might be necessary to create a rule that allows your MIDlet to permit connections to and from a specific website. See "Troubleshooting."

Running the Demo

Launch the Http MIDlet. To test, select the Menu soft key and select Get, Post, or Head to test the selected URL.

Http Test returns the information it obtains. If the information fills the screen use the down arrow to scroll to the end. The amount of information depends on the type of request and on the amount of META information the page provides. To provide body information or content, the page must declare CONTENT-LENGTH as described in RFC 2616.

Using Menu Options

Use the Menu soft key to select an action. The Menu items vary depending on the screen you are viewing.

  • Select Qwerty to set the input type. This activates a submenu with the options Qwerty, 123, Abc, Virtual, and Symbols. This choice is present if you have the option to edit a URL (select Choose, then click the Add soft button).

  • Select GET or press the Get soft key to retrieve data from the selected URI.

  • Select POST to retrieve the post information from the server handling the selected page.

  • Select HEAD to retrieve only the META information from the headers for the selected URI.

  • Select Choose to bring up the current list of web pages. You can chose a different page or add your own page to the list. To specify a new URL, click the Add soft button. The screen displays http://. Type in the rest of the URL. If necessary select Qwerty on the menu and select a different input method. Be sure to end with a slash (/). For example http://www.internetnews.com/. Press the OK soft button. The Http Test screen shows your new URL and prompts for an action.

4.6.2.4 FontTestlet

This MIDlet shows the various fonts available: Proportional, Regular, Regular Italic, Bold Plain, and Bold Italic. Select 1 or 2 from the menu to toggle between the system font (sans serif) and the monospace font.

4.6.2.5 Stock

Like the Http demonstration, this sample uses an HTTP connection to obtain information. Use the same preparation steps as "Http."

Run the Demos project and launch the Stock MIDlet.

By default, the screen displays an empty ticker bar at the bottom. The MIDlet home screen shows four applications: Stock Tracker, What If? Alerts, and Settings. You must add stock symbols before you can use the first three applications.

Add Stock Symbols to the Ticker

To add a stock symbol to the ticker, use the navigation arrows to select Settings.

Select Add Stock.

The display prompts you to enter a stock symbol. Type ORCL and select the Done soft key. The stock you added and its current value is now displayed in the ticker. Add a few more stock symbols, such as IBM and HPQ.

Change the Update Interval

By default the update interval is 15 minutes. Select Settings > Updates to change the interval. Use the navigation arrows to select one of Continuous, 15 minutes, 30 minutes, one hour, or three hours. Select the Done soft key.

Remove a Stock

Select Remove a Stock. You see a list of the stocks you have added. Use the navigation keys to select one or more stocks to remove. Select the Done soft key.

Stock Tracker

Stock Tracker displays a list of the stocks you added and their current values. Click a stock to display additional information. For example, the last trade and the high and low values.

What If?

What If? is an application that asks for the original purchase price and the number of shares you own. It calculates your profit or loss based on the current price.

Select a stock symbol.

Enter the purchase price and the number of shares, then press Calc.

Alerts

This application sends you a notification when the price changes to a value you specify.

From the Stock Menu application home screen, select Alerts.

Select Add.

Select a Stock. The screen prompts, "Alert me when a stock reaches". Enter an integer.

When an alert is created it is placed on the Current Alerts list. To remove an alert, press Remove and select the alert. Select the Done soft key.

When the value is reached you hear a ring and receive a message. For example, Symbol has reached your price point of $value and is currently trading at $current_value. When the alert is triggered it disappears from the Current Alerts list.

4.6.2.6 Tickets

This demonstrates how an online ticket auction application might behave. Click Done to continue to the Welcome To Tickets page. The Choose a Band field displays BootWare & Friends by default, and an auction ticker runs at the bottom of the screen.

Select a band from the dropdown menu. The available auction appears.

Select Make a Bid from the menu. Use the arrow keys to move from field to field. Fill out each field, then select the Next soft key. The application asks you to confirm your bid. Press the Submit button or use the arrow keys to highlight Submit then press the Submit soft key. You receive a Confirmation number. Click Bands to return to the Bands page.

Select Set an Alert from the soft Menu. In the bid field type in a value higher than the current bid and continue bidding as before. You can trigger the alert by making a bid that exceeds your alert value. Your settings determine how often the application checks for changes, so the alert may not sound for a few minutes.

To add a band to the Choose a Band dropdown list, click the Menu soft key and select Add Bands. Type in a band name or a comma-delimited list of names and select Save from the soft menu. After a confirmation message, select Done and you are returned to the Welcome To Tickets page. The added band(s) are displayed at the end of the Choose a Band drop-down menu. If you do not see your bands, use the down arrow key to move to the bottom of the list.

Note, this is only a demonstration. To fully describe the band you must edit the following file:

src\example\auction\NewTicketAuction.java.

To remove a band, click the Menu soft key and select Remove Bands. Check a box for one or more bands. Click the Save soft key.

To display the current settings for ticker display, updates, alert volume, and date, select the Menu soft key and select Show More Info. If desired, use the arrow keys and the select key to change these values. Select the Save soft key.

4.6.2.7 ManyBalls

This MIDlet starts with one ball traveling the screen. Use the up and down arrows to accelerate or decelerate the ball speed (fps). Use the right or left arrows to increase or decrease the number of balls.

4.6.2.8 MiniColor

This MIDlet sets an RGB value. Use navigation keys to change color values.

Keyboard controls work as you would expect. First cursor up or down to highlight a color, and then use left and right keys to lower and raise the value of the selected color.

4.6.2.9 Chooser

The Chooser application uses a variety of controls to change text color, background color, and fonts.

  • Click the Menu soft key and select Text Color. Change the color as described in the "MiniColor" and select the OK soft button.

  • Click the Menu soft key Background Color. Change the color as described in the "MiniColor" and select the OK soft button.

  • Click the Menu soft key and select Fonts. Change the font face, style, and size using the navigation and selection buttons to move through the font options.

    Cursor up and down to highlight a property item by item. The left and right keys jump between lists. Click Select to choose the highlighted option. The chosen option's circle or square is filled with white.

    Click OK to display a sample formatted with your settings.

    Click Exit to return to the home screen.

4.6.2.10 HttpExample

This sample makes an HTTP communication. A popup confirms the transaction was successful.

4.6.2.11 HttpView

This application displays three predefined URLs.

Select a URL, and press the soft buttons to cycle through Head, Headers, Requests, and Errors.

Alternatively, use the menu options.

4.6.2.12 PushExample

This application simulates a feed. As soon as you connect, you receive and display a graphic. Select Done to continue.

4.6.3 Running FPDemo

FPDemo is a simple floating point calculator.

  1. Enter a number in the first field.

  2. To select an operator, highlight the drop-down list and click to select. Cursor down to highlight an operator, then click to make a selection.

  3. Enter a second value.

  4. From the Menu, select Calc to calculate the result.

4.6.4 Running Games

This application features three games: TilePuzzle, WormGame, and PushPuzzle.

TilePuzzle. The desired result, "Rate your mind pal" is shown first. From the soft Menu, select Start. The scrambled puzzle is displayed. The arrow keys move the empty space, displacing tiles accordingly. To change the arrow behavior, select Options from the soft menu, and select reverse arrows, then click OK. From the menu you can Reset, or change options.

WormGame. From the soft Menu, select 1, Launch. Use the arrow keys to move the worm to the green box without touching the edge of the window. When the game is launched, use the soft menu to change game options.

PushPuzzle. Use the blue ball to push the orange boxes into the red squares in the fewest number of moves.

4.6.5 Running Network Demo

This demo has two MIDlets: Socket Demo and Datagram Demo. Each demo requires you to run two emulator instances so that you can emulate the server and client relationship. For example, run the demo on JavaMEPhone1 and JavaMEPhone2.

4.6.5.1 Socket Demo

In this application one emulator acts as the socket server, and the other as the socket client.

  1. In the first emulator, launch the application, then select the Server peer. Select Start. The Socket Server displays a status message that it is waiting on port 5000.

  2. In the second emulator, launch the application, select the Client peer, then select Start. Select Start to launch the client. The Socket Client displays a status message that indicates it is connected to the server on port 5000. Use the down navigation arrow to highlight the Send box. Type a message in the Send box, then select the Send soft key.

    For example, in the client, type Hello Server in the Send box. Select Send from the menu. The server emulator activates a blue light when the message is received.

  3. On the emulator running the Socket Server, the status reads: Message received - Hello Server. You can use the down arrow to move to the Send box and type a reply. For example, Hello Client, I heard you. From the menu, select Send.

  4. Back in the Socket Client, the status is: Message received - Hello Client, I heard you. Until you send a new message, the Send box contains the previous message you sent.

4.6.5.2 Datagram Demo

This demo is similar to Socket Demo. Run two instances of the emulator. One acts as the datagram server, and the other as the datagram client.

  1. In the first emulator, launch Datagram Demo, then select the Server peer. Select Start. Initially, the Datagram Server status is Waiting for connection on port 5555, and the Send box is empty.

  2. In the second emulator, launch Datagram Demo, select the Client peer, ensure the port number is 5555 and select Start. The Datagram Client status is: Connected to server on port 5555. Use the down navigation arrow to highlight the Send box. Type a message in the Send box, then select the Send from the menu. For example, type Hello datagram server. From the menu, select Send.

  3. On the emulator running the Datagram Server, the status displays: Message received - Hello datagram server. You can use the down arrow to move to the Send box and type a reply to the client.

  4. In the Datagram Client, the status field displays the message received from the server. The Send box contains the last message you sent. Overwrite it to send another message.

4.6.6 Running PhotoAlbum

The PhotoAlbum demo displays both static and animated images. When you are displaying an image, you can use the Options soft menu to change the borders. If the image is animated, you can change the speed of the playback.

4.6.7 Running UIDemo

UIDemo showcases a variety of MIDP user interface element implementations. Most elements have some interactive capability (navigate and select) and some allow keypad or keyboard input.

Input interaction is similar across demos. You can select items from lists or type in data.

This demo implements three list selection methods:

  • Exclusive (radio buttons)

  • Multiple (check boxes)

  • Pop-Up (a drop list).

When entering data, you can use the soft menu to apply one of the following input types to text boxes and fields (note, some elements do not use all input types). When a field is selected, the soft Menu label displays Qwerty. Open the menu and you see the input types numbered 1 through 5.

  1. Qwerty. Any character on the keyboard

  2. 123. Any numeral

  3. ABC. Any letter

  4. Predict. Predicts next character based on prior input

  5. Symbols. Opens a list of symbols; click to make a selection.

  6. Virtual. Click keys on a virtual keyboard to enter data.

The Qwerty, 123, and ABC categories act as filters. For example, if you assign 123 to a field and you type "abc", nothing is entered in the field.

When you finish a demo, select the home button to return to the UIDemo launch page:

Figure 4-2 The Home Button

Description of Figure 4-2 follows
Description of "Figure 4-2 The Home Button"

CustomItem. This demo features text fields, and text fields in table form. To type in the table, select a cell, then click to open a text entry panel and type your input. From the menu, select OK.

StringItem. Displays labels, a hyperlink, and a button. The soft menu action varies depending on the selected element.

Gauge. Interactive, non-interactive, indefinite and incremental gauges.

Alert. Uses pop-ups to display alerts. Set the alarm type and the length of the timeout from drop lists. Select the alert type and select the Show soft button.

ChoiceGroup. Radio buttons, check boxes, and pop-ups on one screen.

List. Select exclusive, implicit, or multiple to display the list type on a subsequent screen.

TextBox. Use text fields, radio buttons, check boxes, and pop-ups. Select a text box type and press the Show button.

TextField. Text fields with the six input types.

DateField. Set date and time using drop lists.

Ticker. A scrolling ticker.

4.7 Running IMP-NG Sample Projects

This section describes how to use demos created specifically for the IMP-NG platform (see "IMP-NG"). Because IMP-NG is headless the only user interface is to observe application status in the emulator's external events generator, or in the Output window (or the console if you execute the demo from the command line).

With the exception of I2CDemo, the sample projects in this section can be run on the emulator or on an external device.

See the Oracle® Java ME Embedded Getting Started Guide for the Windows Platform These documents are available on the Java ME documentation site at:

http://docs.oracle.com/javame/embedded/embedded.html

Expand the Oracle Java ME Embedded Version node and then the Getting Started and Release Notes node.

4.7.1 Running the GPIODemo

This demo can be run on an emulator or an external device. The implementations are different, as the emulator uses the external events generator, and the external device supports direct interaction.

4.7.1.1 Running the GPIODemo on the Emulator

  1. Run GPIO demo on an IMP-NG emulator.

  2. Click the GPIO Pins tab. This view approximates the device actions.

  3. Click the Tools menu and select External Events Generator to open the external events generator, and click the GPIO tab. A single click on a button turns on LEDs indicating the button pushed and the pin affected. This information is also written to the Output window.

    Beneath each pin you can click the blue wave button to open the wave generator. The wave generator simulates the frequency and duration of the signal to the LED.

  4. Pressing pin BUTTON 2 in the external events generator changes the state of the pin named LED 5. The button value "Low" corresponds to the LED value "High" and vice versa.

  5. Pressing pin BUTTON 3 changes the state of the port named "LEDS." Consequently pins bound to this port (LED 1, LED 2, LED 3, LED 4) in the following way:

    • If the BUTTON 3 state is "High" the port value is set to 0 and all bound pins are set to "Low."

    • If the BUTTON 3 state "is Low' and the BUTTON 2 state is "Low," the port value is set to 2 and the pins are set to the following state:

      LED 1 - Low, LED 2 - High, LED 3 - Low, LED 4 - Low

    • If the BUTTON 3 state "Low" and the "BUTTON 2" state is "High," the port value is set to 3 and the pins are set to the following states:

      LED 1 - High, LED 2 - High, LED 3 - Low, LED 4 - Low

4.7.1.2 Running the GPIODemo on the Reference Board

The buttons are wired by GPIO. Assuming that you are looking at the board and the Reset button is on the bottom left:

  • Reading from left to right, the LEDS are labeled: PH.3, PH.6, PH.7, PI.10, PG.6, PG.6, PG.8, and PH.2

  • The buttons, from left to right, are Reset, Wakeup, Tamper, and User.

    The Wakeup button corresponds to PH.3 (Listener 1 Pin 5)

    The Tamper button corresponds to PG.6 (Listener 2 Pin 6).

    The User button corresponds to PH.3 and PI.10 (Listener 3 Pin 7)

  • Pressing Tamper turns on the light (PG.6), and releasing turns off the light

  • Pressing the User button when the Tamper button is released turns on lights on for LEDs PH.3 and PH.6.

  • Pressing the User button when the Tamper button is pressed (and as a result the light on LED PG.6 is on) turns on light on LED PH.3 only.

  • Releasing the User button turns the lights off on LEDs PH.3 and PH.6.

4.7.2 Running the I2CDemo

This demo is designed to work with the IMP-NG runtime for Windows 32. It has no user interaction.

  • Launch the I2C demo.

  • In the emulator, click the I2C tab.

    The demo acquires a slave named I2C_Echo, writes data to the slave, and retrieves it. The demo is successful if the Sent Data and Received Data matches.

4.7.3 Running the NetworkDemoIMPNG

This demo is a headless version of "Socket Demo."

You can configure this demo as a server or as a client by editing the application descriptor. You launch two instances of this demo, the first one acts as a server and the second one acts as a client. The client instance attempts to connect to the server instance and if the connection is successful they exchange a message.

4.7.3.1 Running NetworkDemoIMPNG on the Emulator

  1. Create two instance projects of the NetworkDemoIMPNG sample project.

  2. Right click the first project and select Properties.

  3. In the Platform category select the device IMPNGDevice1. In the Application Description category set the value of the following property:

    Oracle-Demo-Network-Mode:Server

  4. Click OK.

  5. Launch the first project. It opens on the emulator IMPNGDevice1 and waits for a connection. You should see messages like the following:

  6. Right click the second project and select Properties.

  7. In the Platform category select the device IMPNGDevice2. In the Application Description category set the value of the following property:

    Oracle-Demo-Network-Mode:Client

  8. Click OK.

  9. Launch the second project. It opens on the emulator IMPNGDevice2.

  10. The client attempts to connect to the server. If successful, you see the following in the output tab of the first project (the server):

    Waiting for connection on port 500
    [AMS-TRACE] MIDlet:NetworkDemoIMPNG status=2
    [AMS-TRACE] MIDlet:NetworkDemoIMPNG status=1
    Connection accepted
    Message received - Client messages
    

    The output of the second project (the client) shows the following:

    [AMS-TRACE] MIDlet:NetworkDemoIMPNG status=2
    [AMS-TRACE] MIDlet:NetworkDemoIMPNG status=1
    Connected to server localhost on port 500
    Message received - Server string
    

4.7.3.2 Running NetworkDemoIMPNG on the Reference Board

You can run one of the instance projects on the board and the other in one of the emulators. Follow these steps to run the client on the board and the server in one of the emulators:

  1. Right click on the first project (the server) and select Properties. In the Platform category select the device IMPNGDevice1 (the emulator) and click OK. In the Application Description category set the value of the property Oracle-Demo-Network-Mode to Server and click OK.

  2. Launch the first project (the server). It runs on the emulator and waits for a connection.

  3. Right click on the second project (the client) and select Properties. In the Platform category select the device IMPNGExternalDevice1 (the board). In the Application Description category set the value of the property Oracle-Demo-Network-Mode to Client and click OK.

    In the Application Descriptor category set the value of the property Oracle-Demo-Network-Address to the IP address of the computer where Eclipse is running and click OK.

  4. Launch the second project (the client). It runs on the board and attempts to connect to the server. If successful, you see the following in the output tab of the first project (the server):

    Connection accepted
    Message received - Client messages
    

    The TCP log of the board (the client) shows the following:

    Connected to server 10.0.0.10 on port 65002
    Message received - Server String
    

4.7.4 Running the PDAPDemoIMPNG

This demo is a headless version of the PDAPDemo file browser in "Browsing Files."

4.7.4.1 Running the PDAPDemoIMPNG on the Emulator

Follow these steps to run the demo on the emulator:

  1. Create test files and directories inside the emulator's file system:

    username\javame-sdk\3.4\work\IMPNGDevice1\appdb\filesystem\root1

  2. Load the project in the Package window.

  3. In the Platform category, select the device IMPNGDevice1 and click OK.

  4. In the Device Selector window, right-click an IMPNGDevice1 emulator.

  5. Select Run Project > PDAPDemoIMPNG from the context menu.

  6. Launch the project.

  7. On the emulator, click the Tools menu and select Manage File System to see a list of mounted file systems.

  8. Open a terminal emulator and create a Telnet connection to localhost on port 65002.


    Note:

    The Telnet negotiation mode must be set to Passive. The negotiation mode can be set inside a Telnet client application (for example, PuTTY), by choosing Category --> Connection --> Telnet --> Passive.


  9. A command line opens where you can browse the emulator's file system. You can use the following commands:

    • cd - change directory

    • ls - list information about the FILEs for the current directory

    • new - create new file or directory

    • prop - show properties of a file

    • rm - remove the file

    • view -View a file's content

4.7.4.2 Running PDAPDemoIMPNG on the Reference Board

Follow these steps to run the demo on the reference board:

  1. Right-click the project and select Properties. In the Platform category, select the device IMPNGExternalDevice1 and click OK.

  2. Launch the project. It runs on the reference board.

  3. Open a terminal emulator and create a raw connection to the IP address of the board on port 65002.

  4. The command line that opens is the same as the one you use when you run the demo on the emulator.

The file system of the demo is stored in the directory java/IMletID inside the SD card, where IMletID is a number that the AMS assigns to an IMlet during its installation.

4.7.5 Running the Pulse Counter (Data Collection) Demo

Pulse counting is the process of sending an electronic pulse to a counter, and then tracking them (via a timestamp) when they arrive. To observe this process, run the following demo on your IMPNG device, using the External Events Generator and the Pulse Counters tab:

  1. Launch the Data Collection Demo.

  2. In the Device Selector, right-click the IMPNGDevice1 emulator and select Run JAR or JAD.

  3. In the file browser, navigate to and select the Data Collection demo JAD file. For example:

    installdir/apps/DataCollectionDemo/dist/DataCollectionDemo.jad
    
  4. When the emulator opens with DataCollectionDemo installed, select DataProcessorIMlet and PulseCounterImlet and click Run.

  5. Click OK twice (once for each IMlet) in the Run IMlet dialog box.

    You do not have to select the debugger, profiler, or memory monitor tool.

  6. Open the External Events Generator by clicking the Tools menu and selecting External Events Generator or clicking the External Events Generator icon.

  7. Click the Pulse Counters tab.

  8. Observe Output Console in the IDE as you click Send Pulse for the first counter, COUNTER_PA0.

    Alternatively, you can select View > Output Console in the emulator menu to open the Output Console window.

    Figure 4-3 Pulse Counter Output

    Description of Figure 4-3 follows
    Description of "Figure 4-3 Pulse Counter Output"

    A pulse timestamp is output for each click of Send Pulse.

4.7.6 Configuring a Pulse Counter

You can configure a pulse counter for an IMPNG device. You can also create a custom IMPNG device with pulse counter capabilities. To do this, follow these steps:

  1. Go to Tools > Java ME > Custom Device Editor.

    For Eclipse users, go to Run > Custom Device Editor.

  2. Select IMP-NG in the Custom Device Editor window and click New... .

  3. In the New IMP-NG Device dialog box, specify a name for the custom device, for example, IMPNGCustomDevice1.

  4. (Optional) you can provide a brief description such as emulator with pulse counter.

  5. Click the Pulse Counters tab.

  6. Click Add for the number of pulse counters you want. For example, click Add four times to create pulse counters with IDs of 0, 1, 2, and 3.

    IDs are automatically assigned to each pulse counter. To unassign an ID, select the row of the desired pulse counter and uncheck the Assign ID option. The unassigned pulse counter is moved to the top of the list.

  7. For each pulse counter, click in the Type column and select the signal trigger type: Falling Pulse Edge, Negative Edge Pulse, Rising Pulse Edge, or Positive Edge Pulse.

  8. Click OK.

You also have the option to bind a pulse counter to an existing GPIO input pin by selecting the specific pin from the dropdown list in the Input Pin column.

The pulse counter type should conform to the trigger value of the binding input GPIO pin. This means that:

  • Pulse counters of the type Falling Pulse Edge can only be bound to input pins with the Falling Edge trigger.

  • Pulse counters of the type Rising Pulse Edge can only be bound to input pins with the Rising Edge trigger.

  • Pulse counters of the type Negative Pulse Edge or Positive Pulse Edge can only be bound to input pins with the Both Edges trigger.

4.7.7 Running the Light Tracker Demo

The Light Tracker demo is specifically aimed at showing off funtionality on a embedded device, such as the Keil MCBSTM32F200 reference platform.

In this demo, a certain number of LEDs are turned on and turned off on the board, in a sequence that you can control. It makes use of the Device Access API and the GPIO Port to demonstrate its functionality. It requires connection of an ADC channel to an on-board potentiometer.

For more information on the setup of the Light Tracker demo, see the LightTrackDemo readme.txt file, in the location where you have installed the Oracle Java ME SDK sample applications. For example:

C:\Documents and Settings\username\Java_ME_SDK\samples\LightTrackDemo

For more information on the Keil MCBSTM32F200 platform, see the Oracle Java ME Embedded Getting Started Guide for the Reference Platform (Keil).

4.7.8 Running the System Controller Demo

The System Controller demo is specifically aimed at showing off funtionality on a embedded device, such as the Keil MCBSTM32F200 reference platform.

The purpose of this demo is to control the lifecycle of IMlets on the reference platform. It makes use of the following functionalities:

  • Multitasking Virtual Machine (MVM)

  • IMlet auto-start

  • Application Management System (AMS) API

  • Logging API

  • Device Access API

  • General Purpose Input/Output (GPIO)

  • Watchdog timer

For more information on the setup of the System Controller demo, see the SystemControllerDemo readme.txt file, in the location where you have installed the Oracle Java ME SDK sample applications. For example:

C:\Documents and Settings\username\Java_ME_SDK\samples\SystemControllerDemo

For more information on the Keil MCBSTM32F200 platform, see the Oracle Java ME Embedded Getting Started Guide for the Reference Platform (Keil).