private InterestingEvent ie;
private boolean somethingHappened;
//Delphi中的寫法
//property OnEvent : TOnEvent read FOnEvent write FOnEvent;
public EventNotifier(InterestingEvent event) {
this.ie = event;
somethingHappened = true;
}
//Delphi中的寫法
//if assigned(FOnEvent) then
//FOnEvent(self,StrLog);
public void doWork() {
if (somethingHappened) {
ie.interestingEvent();
}
}
//
public static void main(String[] argc){
CallMe cm= new CallMe();
EventNotifier ev = new EventNotifier(cm);
ev.doWork();
}
}
//回調函數要用到的接口
interface InterestingEvent {
public void interestingEvent();
}
//要實現調用函數,就要實現回 調函數接口(InterestingEvent )
class CallMe implements InterestingEvent {
private EventNotifier en;
public CallMe() {
en = new EventNotifier(this);
}
public void interestingEvent() {
System.out.println("ddd");
}
}