Description of Java Mobile Software GUI API

Source: Internet
Author: User

I. Preface

The User Interface Programming of handheld devices is different from the desktop Microcomputer Programming. For example, if the display size of a handheld device is small, the display device does not always include a click tool such as a mouse or a pen. For these reasons, it is impossible for us to follow the same rules as the GUI for desktop Microcomputer Programming during GUI programming for handheld devices.

CLDC does not define any GUI functions. On the other hand, the official GUI class of j2's is described in profile files such as MIDP and defined by JAVA community organizations. You may notice that the GUI class described in MIDP is not based on AWT, which seems to be a big problem. Read down.

2. Why not reuse AWT?

After considerable consideration, the MIDP Expert Group decided not to reuse the existing AWT and Swing classes. The reason is as follows:

· AWT was developed for the desktop microcomputer and optimized for this situation.

· AWT sets some user interaction modes. The components of the AWT take into account the point devices such as the mouse, but many handheld devices such as mobile phones only use the keyboard for input.

· AWT has rich features that cannot be implemented on handheld devices. For example, AWT provides extensive support for window management, such as window size and overlapping calls. However, the limited display space of the handheld device makes it impossible to adjust the window above. Therefore, handheld devices do not use the AWT window layout manager.

· When users interact with AWT-based applications, even objects are dynamically created. These objects are only valid for the garbage collector when the related events are processed by the application or system. However, the limited CPU and memory of handheld devices cannot take on such responsibilities.

Iii. MIDP GUI API

For the above reason, MIDP has created its own short GUI, which is quite different from AWT. The midp gui contains two types of low-level and advanced APIs. Each type of AIP has its own event set. This article will discuss and demonstrate examples of using objects through these two types of APIs. API Action events are described in the next chapter.

Advanced APIs are mainly used when mobile device development pays special attention to portability. In order to ensure portability, the API implements advanced abstraction, which gives users little control over the appearance and feeling of controls. For example, you cannot define the visual appearance (shape, color, or font) of an advanced component ). Most interactions with components are encapsulated by the system implementation bodies; applications do not have to care about them. Therefore, the underlying implementation makes necessary adjustments to adapt to the style of hardware and local user interfaces. The classes of high-level APIs are inherited from the javax. microedition. lcdui. Screen class.

Low-layer APIs are rarely abstracted. This design is a place that requires precise control of graphic elements. In this case, applications can also access low-layer input events. This type of API allows applications to precisely control the content displayed on the screen. The javax. microedition. lcdui. Canvas and javax. microedition. lcdui. Graphics classes implement this low-level API. However, it should be clearly pointed out that the MIDlets program for accessing the Low-layer API cannot be transplanted because this API provides detailed operations for accessing specific devices.

1. midp gui Model

The following is a model of how the midp gui works on the kernel. To display on a MIDP device, you need to obtain the Display of the device, which is described by javax. microedition. lcdui. display class. Class Display is the only Display manager that is instantiated when used for each active MIDlet and provides methods to retrieve information about the Display capability of the device.

It is easy to obtain the display information of a device. However, the object itself is not interesting. The more interesting abstraction is screen, which encapsulates and organizes graphical objects and coordinates user input through devices. Screen is described by the javax. microedition. lcdui. Screen Object and displayed by the Display object calling the setCurrent () method. An application can have multiple screens, but at a certain time, only one screen is visible on the screen (the current one ), you can only traverse items on this screen. Figure 1 shows the one-to-many relationship between display and Its Possible multiple screens.

Figure 1. Relationship between display and screens

There are three types of screen in the midp gui:

· Fully encapsulate the screen of complex user interface components (such as List: 2 or TextBox: 3. The structure of these screens is predefined, and applications cannot add other components to these screens.

Figure 2. A set of mutually exclusive options

Figure 3. Example of a text box

· Use the normal screen of the form component. The application can apply text boxes, images, and some simple associated UI components to the form. In this case, the form acts as a container.

· The screen Used in the lower-layer API, such as a Canvas or Graphics object subclass.

2. Lcdui package

All midp gui classes are included in the javax. microedition. lcdui package. The package contains 3 interfaces and 21 classes. For details, see table 1 and table 2.

Table 1: lcdui Interface

Interface Description
Choice Defines an API for the user interface component, which is selected from the predefined options
CommandListener Used by applications to retrieve high-level events from the implementation process
ItemStateListener When the application needs to receive an event (the event represents a change in the internal status of the interaction item ),

Table 2: lcdui

Class Description
Alert A screen that displays data to the user and waits for a period of time before the next screen is displayed.
AlertType This class indicates the Alert type above.
Canvas This is a basic class for applications that need to process low-level events and send graphical calls to the screen.
ChoiceGroup To place a set of optional elements in a form
Command Used to encapsulate the semantic information of an action.
DateField An editable component used to describe the date and time information displayed on the calendar on the form
Display Used to describe the input devices of the Display Manager and System
Displayable Objects that can be displayed
Font Class that describes the font and its size
Form A screen contains any combination of many items (images, text, text fields, grouping groups, etc.)
Gauge Display the bar code of a value in the form
Graphics This class provides simple 2D ry coloring capabilities
Image Class for storing image data
ImageItem When you add an image object to form or alert, you are responsible for its layout control.
Item It is a base class for all components that can be added to Form or Alert.
List Contains a series of screen controls
Screen Base class of the high-level user interface class used
StringItem This item can store strings
TextBox Screen controls that allow users to enter and edit text
TextField Editable text controls that can be placed on a form
Ticker A text that is displayed across the screen. It can be attached to all screens except Canvas.

Displays the main classes and their relationships.

Figure 4. Class relationship diagram between main classes in the package

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.