GUI和AWT事件模型

上传人:tang****xu6 文档编号:327675301 上传时间:2022-07-27 格式:DOCX 页数:2 大小:10.78KB
返回 下载 相关 举报
GUI和AWT事件模型_第1页
第1页 / 共2页
GUI和AWT事件模型_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

《GUI和AWT事件模型》由会员分享,可在线阅读,更多相关《GUI和AWT事件模型(2页珍藏版)》请在金锄头文库上搜索。

1、GUIAWTEventModelGUIGraphicUserInterfaceB/SServerHTTPServerC/SAWT(AbstractWindowTookit)SWINGJFrame,JPanel234FrameBorderLayoutPanelPanelFrameFlowLayoutAWTMotherMother600JDKEventSourceEventObjectEventListenerjava.util.EeventObjectjava.util.EventListenerclassMother/privateListlist=newArrayList();/public

2、voidaddHomeWorkListener(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

3、();classHomeWorkEventextendsEventObject/publicHomeWorkEvent(Objecto)super(o);interfaceHomeWorkListenerextendsEventListener/voidhomework(HomeWorkEvento);classXiaoQiangimplementsHomeWorkListener/1publicvoidhomework(HomeWorkEvento)/classXiaoMingimplementsHomeWorkListener/2publicvoidhomework(HomeWorkEve

4、nto)(/classXiaoFendimplementsHomeWorkListener/3publicvoidhomework(HomeWorkEvento)/XXXEventHomeWorkEventXXXListenerHomeWorkListenergetSource()1Gril13579(Boy)Boy246810BoyGrilEmotionEventextendsEventObjectEmotionListenerBoyCoding:publicclassGril/privateStringname;privateListlist=newArrayList();/publicG

5、ril(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(

6、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);/publicinte

7、rfaceEmotionListenerextendsEventListener(voidwhatCanIdoWhenHappy(EmotionEvente);voidwhatCanIdoWhenSad(EmotionEvente);/:BoypublicclassBoyimplementsEmotionListener(privateStringname;publicBoy(Stringname)(=name;publicStringgetName()(returnname;publicvoidwhatCanIdoWhenHappy(EmotionEvente)(Objecto=e.getS

8、ource();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=new

9、ArrayList();/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()Time

10、Listenertl=(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

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号