Java???y???????
???????????? ???????[ 2013/6/8 10:05:21 ] ????????
????????????????????????????
/*
* ????????????????????????????????????
*/
interface InterestingEvent {
public void interestingEvent();
}
class EventNotifier {
private InterestingEvent ie; //д??private List<InterestingEvent> eventList?????????????
private boolean somethingHappened;
public EventNotifier(InterestingEvent ie) {
this.ie = ie;
this.somethingHappened = false;
}
public void setHappened() {
this.somethingHappened = true;
}
public void doWork() {
if (somethingHappened) {
ie.interestingEvent();
}
}
}
class ButtonPressedEvent implements InterestingEvent {
@SuppressWarnings("unused")
private EventNotifier en;
public ButtonPressedEvent() {
en = new EventNotifier(this);
}
public void interestingEvent() {
System.out.println("button pressed ");
}
}
class EventNotifierTest {
public static void test() {
//????????????÷????????е??????????????????????????“???Client????”???????
EventNotifier en = new EventNotifier(new ButtonPressedEvent());
en.setHappened();
en.doWork();
EventNotifier en2 = new EventNotifier(new InterestingEvent(){
public void interestingEvent() {
System.out.println("inputtext change ");
}
});
en2.setHappened();
en2.doWork();
}
}
//????????????????
public class JavaInterfaceCallBack {
public static void main(String[] args) {
ChangeNameTest.test();
EventNotifierTest.test();
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11