资源预览内容
亲,该文档总共2页全部预览完了,如果喜欢就下载吧!
资源描述
GUIAWTEventModelGUIGraphicUserInterfaceB/SServerHTTPServerC/SAWT(AbstractWindowTookit)SWINGJFrame,JPanel234FrameBorderLayoutPanelPanelFrameFlowLayoutAWTMotherMother600JDKEventSourceEventObjectEventListenerjava.util.EeventObjectjava.util.EventListenerclassMother/privateListlist=newArrayList();/publicvoidaddHomeWorkListener(HomeWorkListenerhwl)list.add(hwl);/publicvoidremoveHomeWorkListener(HomeWorkListenerhwl)(list.remove(hwl);publicvoidnotify()(/6OCLOLKHomeWorkEventevent=newHomeWorkEvent(this);Iteratorit=list.iterator();while(it.hasNext()HomeWorkListenerh=(HomeWorkListener)it.next();h.homework();classHomeWorkEventextendsEventObject/publicHomeWorkEvent(Objecto)super(o);interfaceHomeWorkListenerextendsEventListener/voidhomework(HomeWorkEvento);classXiaoQiangimplementsHomeWorkListener/1publicvoidhomework(HomeWorkEvento)/classXiaoMingimplementsHomeWorkListener/2publicvoidhomework(HomeWorkEvento)(/classXiaoFendimplementsHomeWorkListener/3publicvoidhomework(HomeWorkEvento)/XXXEventHomeWorkEventXXXListenerHomeWorkListenergetSource()1Gril13579(Boy)Boy246810BoyGrilEmotionEventextendsEventObjectEmotionListenerBoyCoding:publicclassGril/privateStringname;privateListlist=newArrayList();/publicGril(Stringname)=name;publicStringgetName()returnname;*/publicvoidaddEmotionListener(EmotionListenere)(list.add(e);/*/publicvoidremoveEmotionListener(EmotionListenere)(list.remove(e);/publicvoidfire()(EmotionEventevent=newEmotionEvent(this);for(inti=0;i10;i+)if(i%2=0)Iteratorit=list.iterator();while(it.hasNext()EmotionListenerel=(EmotionListener)it.next();el.whatCanldoWhenHappy(event);elseIteratorit=list.iterator();while(it.hasNext()EmotionListenerel=(EmotionListener)it.next();el.whatCanldoWhenSad(event);/publicclassEmotionEventextendsEventObject(publicEmotionEvent(Objecto)(super(o);/publicinterfaceEmotionListenerextendsEventListener(voidwhatCanIdoWhenHappy(EmotionEvente);voidwhatCanIdoWhenSad(EmotionEvente);/:BoypublicclassBoyimplementsEmotionListener(privateStringname;publicBoy(Stringname)(=name;publicStringgetName()(returnname;publicvoidwhatCanIdoWhenHappy(EmotionEvente)(Objecto=e.getSource();Grilg=(Gril)o;System.out.println(name+saidto+g.getName()+,youhappy,Iamhappy);publicvoidwhatCanIdoWhenSad(EmotionEvente)Objecto=e.getSource();Grilg=(Gril)o;System.out.println(name+saidto+g.getName()+,yousad,Iamsosad.);Time,2022OlympicsWorldCupOlympicsWorldCupCoding:classTime/privateListlt=newArrayList();/privateintyear;/publicintgetYear()returnyear;publicvoidaddTimeListener(TimeListenert)lt.add(t);publicvoidremoveTimeListener(TimeListenert)lt.remove(t);publicvoidaction()TimeEventevent=newTimeEvent(this);for(inti=2022;i=3000;i+)this.year=i;/Iteratorit=lt.iterator();while(it.hasNext()TimeListenertl=(TimeListener)it.next();/disp()tl.disp(event);/classTimeEventextendsEventObject(publicTimeEvent(Objecto)(super(o);/interfaceTimeListenerextendsEventListener(voiddisp(TimeEventevent);/1classOlympicsimplementsTimeListener(publicvoiddisp(TimeEventevent)(Timet=(Time)event.getSource();if(t.getYear()%4=0)(System.out.println(t.getYear()+);/2classWorldCupimplementsTimeListener(publicvoiddisp(TimeEventevent)(Timet=(Time)event.getSource();if(t.getYear()%4=2)(System.out.println(t.getYear()+);1N77
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号