What Are the Different Types of Event Management Qualifications?

In the Java language, when a user interacts with a GUI component, the GUI component can fire a corresponding event. For example, a user pressing a button, scrolling text, moving the mouse, or pressing a key will generate a corresponding event. Java provides Perfect event processing mechanism, which can monitor events, identify event sources, and complete event processing. [1]

The event processing mechanism is an event processing framework, and its design purpose is to transform the GUI interactive actions (click, menu selection, etc.) into calling related event handlers for processing. Since JDK 1.1, Java has adopted a delegation-based model. The event source can authorize all possible events in its own to different event handlers for processing.
Since the window manager cannot directly call the event handler provided by the developer, the event model must be told at runtime which routine is used to handle the event. Therefore, in order to obtain any event, the developer must notify the window system in advance, and cause it to send the event to the event handler provided by itself, and register the event handler as a callback routine in the window manager. Connect it to the component that generated the event. [2]
There are several constituent elements in the event processing mechanism and the similarities between them: the relationship is very important, mainly including events, event sources, event listeners, event adapters, and so on.
1) Event: It can be understood as a collection of certain types of operation actions on a component. For example, clicking a button, entering a string in a text box, selecting a menu option, selecting a radio button, etc. can all be considered an action. The use of a mouse to click a button, enter a button, remove a button, press a button, release a button, etc. can be considered as the same type of action operation, because it is completed by the mouse. Can be described uniformly by mouse events. Java classifies events into several types according to the way events are generated, such as mouse events, keyboard events, window events, selection events, etc.
2) Event Source: It can be understood as the source of the event, that is, the component that generated the event.
There are two types of event handling mechanisms on the Android platform, one is a callback mechanism, and the other is a listener interface mechanism.

Event handling mechanism event processing based on callback mechanism

In the Android platform, each View has its own callback method for handling events. Developers can override these callback methods in the View to achieve the required response events. When an event is not handled by any View, the corresponding callback method in the Activity will be called. Android provides the following callback methods for users to use:
(1) public boolean onKeyDown (int keyCode, KeyEvent event).
This method is an interface KeyEvent. The abstract method in Callback. All Views implement this interface and override this method. This method is used to capture the event that the mobile phone keyboard is pressed.
(2) public boolean onKeyUp (int keyCode, KeyEvent event).
This method is also the interface KeyEvent. An abstract method in Callback, and all Views also implement this interface and override this method. The onKeyUp method is used to capture the event that the mobile phone keyboard key is raised.
(3) public boolean onTouchEvent (MotionEvent event).
This method is defined in the View class, and all View subclasses override this method. Applications can use this method to handle touch events on the phone screen.
(4) public boolean onTrackballEvent (MotionEvent event).
Trackball processing method onTrackBallEvent. All Views also implement this method.
(5) protected void onFocusChanged (boolean gainFocus, int direction, Rect previously Focuse-dReet).
This method is a callback method for focus change. When a control overrides this method, when the focus changes, it will automatically call this method to handle the focus change event.

The event processing mechanism is based on the event processing of the listening interface

The listener-based event processing mainly involves the following three objects.
(1) EventSource (event source).
The place where the event occurs is usually the various components, such as windows, buttons, menus, and so on.
(2) Event.
An event encapsulates a specific event that occurs on an interface component. It is usually a user operation. If a program needs to obtain information about events that occur on an interface component, it is usually obtained through the Event object.
(3) EventListener (event listener).
Responsible for listening to events from the event source and responding to various events accordingly.

Android Event handling mechanism commonly used event listeners in Android

(1) OnClickListener interface.
This interface handles click events. In the touch mode, it is the combined action of pressing and lifting on a certain View, while in the keyboard mode, it is the event of clicking a OK key or pressing the trackball after a certain view gains focus.
(2) OnLongClickListener interface.
The OnLongcllickListener interface is basically the same as the OnClickListener interface introduced earlier, except that this interface is a capture interface for View long-press events, that is, events that are triggered when a View is pressed for a long time.
(3) OnFocusChangeListener interface.
The OnFocusChangeListener interface is used to handle events that change the focus of the control. If this interface is registered, the callback method in this interface will be triggered when a control loses focus or gets focus.
(4) OnKeyListener interface.
OnKeyListener is an interface that listens to the keyboard of a mobile phone. By registering the listener to a View, when the View gets focus and there are keyboard events, the callback method in this interface will be triggered.
(5) OnTouchListener interface.
The OnTouchListener interface is a monitoring interface used to handle mobile phone screen events. This event is triggered when touch, press, lift, or slide actions within the scope of the View.
(6) OnCreateContextMIenuLitstener interface.
The OnCreateContextMenuListener interface is a listening interface used to handle context menu display events. This method is another way to define and register a context menu.
In the "Android Mobile Lianliankan" project, we will use the monitoring interface-based method for event processing, and use the OnClickListener interface to capture the user's click on the game map. [4]

IN OTHER LANGUAGES

Was this article helpful? Thanks for the feedback Thanks for the feedback

How can we help? How can we help?