Programming MIDlets for Interactive Behavior Wisconsin

Discover how to add commands to a MIDlet and how those commands are presented to the user in the Sun cell phone emulator. You will also learn how to produce interactive behavior within a MIDlet.

Local Companies

Electroniclaim
262-240-9700
11357 N. Port Washington Rd
Mequon, WI
R S InfoCon, Inc.
262-898-7456
2320 Renaissance Blvd
Sturtevant, WI
IFS
414-577-5191
12000 W. Park Place
Milwaukee, WI
HarrisData
262-784-9099
13555 Bishop's Court, Suite 300
Brookfield, WI
Acumium
608 310 9700 x 522
5133 West Terrace Drive Suite 300
Madison, , WI
Xorbix Technologies Inc.
414-277-5044
759 N. Milwaukee St.
Milwaukee, WI
Wireless Direct
1.866.707.8498
BOX 71101
shorewood, WI
Visionary Computer Solutions
262-365-9430
PO Box 406
Grafton, WI
HarrisData
800-225-0585
13555 Bishops Court
Brookfield, WI
R.E. Coker and Associates, Inc.
262-723-8104
108 W Court St.
Elkhorn, WI


Programming MIDlets for Interactive Behavior

provided by: 
Originally published at Internet.com


Java Programming Notes # 2586 * Preface * Viewing tip * Figures * Listings * Supplementary material * General background information * Preview * Discussion and sample code * The Command class * The MIDlet named Command02 * The CommandListener interface * The MIDlet named Command03 * The MIDlet named Command04 * The ItemCommandListener interface * The MIDlet named Command05 * Run the programs * Summary * What's next? * Resources * Complete program listings * Copyright * About the author -----------------------------------

Preface

This is one in a series of tutorial lessons designed to teach you how to write programs using the Sun Java Wireless Toolkit for CLDC. The first lesson was titled Getting Started with MIDlets and the Sun Java Wireless Toolkit for CLDC. The previous lesson was titled Using Forms and Items in MIDlets (see Resources).

What you will learn

I will begin by illustrating and explaining the addition of Command objects to a MIDlet and showing you how those commands are presented to the user in the Sun cell phone emulator.

Interactive behavior of a MIDlet is achieved, not through commands, but rather through the use of a CommandListener object or an ItemCommandListener object. I will illustrate and explain the setting and subsequent processing of a CommandListener in one of the simplest ways possible.

Following that, I will present and explain a much more substantive MIDlet. This MIDlet illustrates the use of CommandListener objects to handle seven of the eight possible types of commands and shows how to use commands to navigate through the different pages of a MIDlet that is composed of several pages.

Finally, I will illustrate and explain the use of an ItemCommandListener to handle an ITEM command on an item contained in a Form.

Viewing tip

I recommend that you open another copy of this document in a separate browser window and use the following links to easily find and view the figures and listings while you are reading about them.

Figures

* Figure 1. Partial class hierarchy for MIDP 2.0. * Figure 2. Sun cell phone emulator with nine commands showing. * Figure 3. The commandAction method. * Figure 4. The MIDlet named Command03 in the Sun emulator. * Figure 5. Sun emulator screen when the MIDlet is not running. * Figure 6. General behavior of each command type. * Figure 7. Screen shot of Command04 in the Sun cell phone emulator. * Figure 8. ChoiceGroup selected in Sun cell phone emulator. * Figure 9. Result of activating the GetSelection command.

Listings

* Listing 1. Beginning of MIDlet class named Command02. * Listing 2. Add four commands to the TextBox. * Listing 3. Add four more commands to the TextBox. * Listing 4. Remaining code in the MIDlet named Command02. * Listing 5. Beginning of the class for the MIDlet named Commond03. * Listing 6. Add two commands to the TextBox. * Listing 7. Set a commandListener object on the TextBox. * Listing 8. Remaining code for the MIDlet named Command03. * Listing 9. Beginning of the class for the MIDlet named Command04. * Listing 10. Set a CommandListener on the page 1 TextBox. * Listing 11. Remaining code for the MIDlet named Command04. * Listing 12. Beginning of the class for the MIDlet named Command05. * Listing 13. Append a StringItem and an ImageItem to the Form. * Listing 14. Append a ChoiceGroup object to the Form. * Listing 15. Add an ITEM command and an ItemCommandListener to the ChoiceGroup object. * Listing 16. Source code for the MIDlet named Command02. * Listing 17. Source code for the MIDlet named Command03. * Listing 18. Source code for the MIDlet named Command04. * Listing 19. Source code for the MIDlet named Command05.

Supplementary material

I recommend that you also study the other lessons in my extensive collection of online Java tutorials. You will find a consolidated index at www.DickBaldwin.com.

General background information

If you were expecting the interactive programming capability of J2ME to be similar to the JavaBeans or Delegation Event models in J2SE (see Resources), you are in for a big disappointment. The model is more akin to the somewhat rudimentary models that I describe in the following tutorial lessons. * Event Handling in JDK 1.0.2, The Event Class (see Resources) * Handling Events in Extended Components without Listener Objects (see Resources)

Partial class hierarchy for MIDP 2.0

A partial class hierarchy for MIDP 2.0 is shown in Figure 1.

Figure 1. Partial class hierarchy for MIDP 2.0. * Object * Displayable * Screen * TextBox * Alert * List * Form * Canvas (abstract) * GameCanvas (abstract) * Display * Ticker * AlertType * Image * Item * Gauge * ChoiceGroup * CustomItem

Author: Richard G. Baldwin

Read article at Internet.com site

Featured Local Company

Wireless Direct

1.866.707.8498
BOX 71101
shorewood, WI
http://www.prepaidwireless.2ya.com

Regional Articles
- Programming MIDlets for Interactive Behavior Appleton WI
- Programming MIDlets for Interactive Behavior Baraboo WI
- Programming MIDlets for Interactive Behavior Beaver Dam WI
- Programming MIDlets for Interactive Behavior Beloit WI
- Programming MIDlets for Interactive Behavior Brookfield WI
- Programming MIDlets for Interactive Behavior Burlington WI
- Programming MIDlets for Interactive Behavior Cedarburg WI
- Programming MIDlets for Interactive Behavior Chippewa Falls WI
- Programming MIDlets for Interactive Behavior Cudahy WI
- Programming MIDlets for Interactive Behavior De Pere WI
- Programming MIDlets for Interactive Behavior Delavan WI
- Programming MIDlets for Interactive Behavior Eau Claire WI
- Programming MIDlets for Interactive Behavior Elkhorn WI
- Programming MIDlets for Interactive Behavior Fond Du Lac WI
- Programming MIDlets for Interactive Behavior Fort Atkinson WI
- Programming MIDlets for Interactive Behavior Franklin WI
- Programming MIDlets for Interactive Behavior Green Bay WI
- Programming MIDlets for Interactive Behavior Hartland WI
- Programming MIDlets for Interactive Behavior Janesville WI
- Programming MIDlets for Interactive Behavior Kaukauna WI
- Programming MIDlets for Interactive Behavior Kenosha WI
- Programming MIDlets for Interactive Behavior La Crosse WI
- Programming MIDlets for Interactive Behavior Lake Geneva WI
- Programming MIDlets for Interactive Behavior Manitowoc WI
- Programming MIDlets for Interactive Behavior Marinette WI
- Programming MIDlets for Interactive Behavior Marshfield WI
- Programming MIDlets for Interactive Behavior Menasha WI
- Programming MIDlets for Interactive Behavior Menomonee Falls WI
- Programming MIDlets for Interactive Behavior Menomonie WI
- Programming MIDlets for Interactive Behavior Merrill WI
- Programming MIDlets for Interactive Behavior Middleton WI
- Programming MIDlets for Interactive Behavior Milwaukee WI
- Programming MIDlets for Interactive Behavior Mosinee WI
- Programming MIDlets for Interactive Behavior Mukwonago WI
- Programming MIDlets for Interactive Behavior Muskego WI
- Programming MIDlets for Interactive Behavior Neenah WI
- Programming MIDlets for Interactive Behavior New Berlin WI
- Programming MIDlets for Interactive Behavior Oak Creek WI
- Programming MIDlets for Interactive Behavior Oconomowoc WI
- Programming MIDlets for Interactive Behavior Onalaska WI
- Programming MIDlets for Interactive Behavior Oshkosh WI
- Programming MIDlets for Interactive Behavior Pewaukee WI
- Programming MIDlets for Interactive Behavior Racine WI
- Programming MIDlets for Interactive Behavior Rhinelander WI
- Programming MIDlets for Interactive Behavior Rice Lake WI
- Programming MIDlets for Interactive Behavior River Falls WI
- Programming MIDlets for Interactive Behavior Schofield WI
- Programming MIDlets for Interactive Behavior Shawano WI
- Programming MIDlets for Interactive Behavior Sheboygan WI
- Programming MIDlets for Interactive Behavior South Milwaukee WI
- Programming MIDlets for Interactive Behavior Stevens Point WI
- Programming MIDlets for Interactive Behavior Sturgeon Bay WI
- Programming MIDlets for Interactive Behavior Sun Prairie WI
- Programming MIDlets for Interactive Behavior Superior WI
- Programming MIDlets for Interactive Behavior Thiensville WI
- Programming MIDlets for Interactive Behavior Two Rivers WI
- Programming MIDlets for Interactive Behavior Watertown WI
- Programming MIDlets for Interactive Behavior Waukesha WI
- Programming MIDlets for Interactive Behavior Waupaca WI
- Programming MIDlets for Interactive Behavior Wausau WI
- Programming MIDlets for Interactive Behavior West Bend WI
- Programming MIDlets for Interactive Behavior Whitewater WI
- Programming MIDlets for Interactive Behavior Wisconsin Rapids WI
Related Local Events
2008 Early Stage Symposium
Dates: 11/5/2008 - 11/6/2008
Location: Monona Terrace
Madison WI
View Details

Wisconsin Entrepreneurs' Conference
Dates: 6/9/2008 - 6/10/2008
Location: Hyatt Regency Hotel
Milwaukee WI
View Details
Rate Article
     
Articles Insider

Rss   Delicious   Digg   Add To My Yahoo   Add To My Google   Bookmark   Search Plugin

Topics:
Advertising Engineering Home Services Software
Business Services Entertainment Industrial Goods & Services Technology
Career Family Insurance Telecommunications
Cars Financial Services Internet Transportation & Logistics
Computer Hardware Food & Beverage Legal Travel
Construction Health Real Estate Wedding
Education Home Electronics Retail & Consumer Services