Swing 简明教程

SWING - Event Listeners

事件侦听器表示负责处理事件的接口。Java 提供各种事件侦听器类,但我们只讨论使用最频繁的那些类。每个事件侦听器方法的一个方法只有一个参数,该参数是一个对象,它是 EventObject 类的子类。例如,鼠标事件侦听器方法接受 MouseEvent 的实例,其中 MouseEvent 派生自 EventObject。

Event listeners represent the interfaces responsible to handle events. Java provides various Event listener classes, however, only those which are more frequently used will be discussed. Every method of an event listener method has a single argument as an object which is the subclass of EventObject class. For example, mouse event listener methods will accept instance of MouseEvent, where MouseEvent derives from EventObject.

EventListner Interface

它是一个标记接口,每个侦听器接口都必须扩展它。此类在 java.util 中定义。

It is a marker interface which every listener interface has to extend. This class is defined in java.util package.

Class Declaration

以下是 java.util.EventListener 接口的声明 −

Following is the declaration for java.util.EventListener interface −

public interface EventListener

SWING Event Listener Interfaces

以下是常用事件侦听器的列表。

Following is the list of commonly used event listeners.

Sr.No.

Class & Description

1

ActionListenerThis interface is used for receiving the action events.

2

ComponentListenerThis interface is used for receiving the component events.

3

ItemListenerThis interface is used for receiving the item events.

4

KeyListenerThis interface is used for receiving the key events.

5

MouseListenerThis interface is used for receiving the mouse events.

6

WindowListenerThis interface is used for receiving the window events.

7

AdjustmentListenerThis interface is used for receiving the adjustment events.

8

ContainerListenerThis interface is used for receiving the container events.

9

MouseMotionListenerThis interface is used for receiving the mouse motion events.

10

FocusListenerThis interface is used for receiving the focus events.