[scrollable messages PIC] J2ME Chapter 1.   Scrollable Messages

 

[ This chapter does not appear in the book. ]

The ScrollMBDemo MIDlet is a test rig for a CustomItem subclass called ScrollableMessagesBox. ScrollableMessagesBox displays a list of messages, and allows the user to scroll up and down through them. Since the messages box is a CustomItem, it can be easily integrated into forms alongside other items.

The screenshot on the right shows ScrollMBDemo in action.

The user types a message into the "Enter:" textfield at the top of the form, presses the "Send" command, and the message is added to the messages box. The messages are automatically numbered, starting from 1.

Once the box has filled up, the messages start scrolling upwards, so the latest messages remain visible.

Two commands, "Up" and "Down", appear in the commands menu when the user tabs into the messages box. The commands permit the user to scroll up and down through the messages list. Scrolling is also possible by pressing the up and down keys (which are mapped to the '2' and '8' keys in Sun's WTK). Fast scrolling is available by holding down the up and down keys.

The box only stores a limited number of messages (roughly 1.5 times the number of lines that can be drawn in the box). When this limit is reached, older messages are discarded to make room for new ones.

A drawback of ScrollableMessagesBox is that scrolling is controlled by commands and keys only; it's not possible to click on an arrow, or drag in the bar, to trigger text movement.

The ScrollableMessagesBox class is used in several of our J2ME network examples, as a convenient way of displaying the lengthy communication between a user and other participants in the system. [Note: these examples are not yet available online (August 2005). Sorry.]

ScrollableMessagesBox is also a reasonably-sized example of how to utilize CustomItem. It illustrates how to specify an item's size, draw to its canvas, catch key presses, and respond to item-specific commands. Two aspects of CustomItem which aren't present are off-screen editing and traversal, but I'll talk about those briefly at the end of the chapter.

 

Downloads


Navigation:


Dr. Andrew Davison
E-mail: ad@fivedots.coe.psu.ac.th
Back to my home page