Tune process in Java

xiaoxiao2021-03-06  14

The original text is very long, in fact, it is very simple, you can write a probably frame. First, define an interface class generated events include such a class public interface InterestingEvent {// This is just a regular method so it can return something or // take arguments if you like public void interestingEvent ();.} Public class EventNotifier { private InterestingEvent ie; private boolean somethingHappened; public EventNotifier (InterestingEvent event) {// Save the event object for later use ie = event;. // Nothing to report yet somethingHappened = false;.} // ... public void doWork ( ) {// check the Predicate, Which is set elsewhere. If (Somethinghappend) {// Signal the evening. IE.interestingEvent ();} // ...} // ...} and then The activated event process can be implemented. public class CallMe implements InterestingEvent {private EventNotifier en; public CallMe () {// Create the event notifier and pass ourself to it en = new EventNotifier (this);..} // Define the actual handler for the event public void interestingEvent ( ) {// wow! Something real intending must harve {// // do something ...} // ...}

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

New Post(0)