Event source generation mode

xiaoxiao2021-03-06  70

There is an event:

Interface xxxlistener {

Void Event1happens (String Param);

Void Event2happens (String Param);

}

Can be a corresponding class:

Class XXXDispatcher Extends Vector Implements XXXListener {

Public void Event1happens (String param) {

For (XXXListener Listener: this) {

Listener.event1happens (param);

}

}

Public void Event2happens (String param) {

For (XXXListener Listener: this) {

Listener.event2happens (param);

}

}

}

Implements XXXListener is not a must, but most of the IDE supports direct imports, you can automatically generate all methods.

Then the event source addXXXListener and RemovexxxListener call XXXDispatcher.add, Remove

You need to trigger an event 1 directly call xxxdispatcher.event1happens (param);

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

New Post(0)