J2ME MIDP provides graphic elements to choose from Lastking Blog

xiaoxiao2021-03-06  79

MIDP API despite maintenance of a limited frame, it still provides a complete collection of UI elements. The following is some of the most important UI elements:

Alert is used to display information about exceptions or errors on the screen. Choice is used to achieve selection from a set of options. Choicegroup provides a set of related options. FORM is a container of other UI elements. List provides a list of options. StringItem acts as a DISPLAY-ONLY string. Textbox is a screen display that allows users to enter and edit text. TextField allows users to enter and edit text. Multiple TextField can be placed in an Form. DateField is an editable component for representing date and time information. Datefield can be placed in Form. Ticker can scroll-on the text for text.

A sample application: One of the famous features of the phone calendar J2ME is its date processing in the restricted environment. The Datefield UI element provided by J2ME is an editable component, which is used to represent calendar information (ie, the date and time). In this section, we will use the DateField and Date functions to develop a J2ME application, which is used to display a scroll calendar on the mobile phone UI.

// Import of API classesimport javax.microedition.midlet *;. Import javax.microedition.lcdui *;. Import java.util *;. // A first MIDlet with simple text and a few commands.public class PhoneCalendar extends MIDletimplements CommandListener, ItemStateListener {// The commandsprivate Command exitCommand; // The display for this MIDletprivate Display display; // Display items eg Form and DateFieldForm displayForm; DateField date; public PhoneCalendar () {display = Display.getDisplay (this); exitCommand = new Command ("Exit", command.screen, 1); Date = new datefield ("select to date", datefield.date);} // start the midlet by create the form and // associarating the EXIT Command and Listener.public Void startApp () {displayForm = new Form ( "Quick Calendar"); displayForm.append (date); displayForm.addCommand (exitCommand); displayForm.setCommandListener (this); displayForm.setItemStateListener (this); display.setCurrent (displayForm); } public void itemStatechanged (item item) {// get the values ​​from changed item} // Pause is a no-op when there is no background // activities or record stores to be closed.public void pauseApp () {} // Destroy must cleanup everything not handled // by the garbage collector.public void destroyApp (boolean unconditional) {} // Respond to commands. Here we are only implementing // the exit command. In the exit command, cleanup and // notify that the MIDlet has been destroyed.public void commandAction (Command c, Displayable s) {if (c == EXITCOMMAND) {DestroyApp (false); notifydestroyed ();}}} author blog:

http://blog.9cbs.net/lastking/

转载请注明原文地址:https://www.9cbs.com/read-108759.html

New Post(0)