Author: Han Ru

Company: Program Ka (Beijing) Technology Co., LTD

Hong Meng Bus columnist

The Ability application brings to the screen a user interface that displays all content that can be viewed and interacted with by the user.

All user interface elements in an application are made up of Component and ComponentContainer objects. Component is an object drawn on the screen that the user can interact with. ComponentContainer is a container that holds other Component and ComponentContainer objects.

The Java UI framework provides subclasses of Component and ComponentContainer, the components that create user interfaces (UIs), including common components (text, buttons, images, lists, etc.) and common layouts (for example: DirectionalLayout and DependentLayout). Users can interact with components and get responses.

All UI operations should be set up in the main thread.

Components and layout

User interface elements are collectively referred to as components, which are combined to form a layout based on a hierarchical structure. Components can neither be displayed nor interacted with before they are added to the layout, so a user interface contains at least one layout. In the UI framework, the specific layout class is usually named XXLayout. The complete user interface is a layout, and parts of the user interface can also be a layout. The layout holds Component and ComponentContainer objects.

Component container

  • Component: Provides content display and is the base class for all components in the interface. Developers can set event handling callbacks to Component to create an interactive Component. The Java UI framework provides common interface elements, also known as components, that inherit directly from Component or its subclasses, such as Text, Image, and so on.
  • ComponentContainer: Holds Component or ComponentContainer objects as containers and lays them out. Java UI framework provides some standard Layout function containers, which inherit from ComponentContainer, generally end with “Layout”, such as DirectionalLayout, DependentLayout, etc.

Figure 1 Component structure

UI class inheritance structure diagram:

Third, LayoutConfig

Each layout provides a LayoutConfig for the child Components to set layout properties and parameters. Specifying layout properties can restrict how the child Components appear in the layout. For example, “width” and “height” are the most basic layout attributes that specify the size of the component.

Figure 2 LayoutConfig

Component tree

A layout organizes Component and ComponentContainers in a tree-like hierarchy. Such a layout is called a Component tree. A component tree is characterized by a single root component, and other components have only one parent node. The relationship between components is governed by the rules of the parent node.

More:

1. Community: Hongmeng Bus www.harmonybus.net/

2. HarmonyBus

3, technical exchange QQ group: 714518656

4. Video courses: www.chengxuka.com