Java第06章--2(布局与事件处理)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

JavaJavapenggang@mail.hust.edu.cn12AWT(AbstractWindowToolkit)3Swing4566.44Java(LayoutManager)4ƒsetLocation(),setSize(),setBounds()ƒsetLayout(null)setLocation(),setSize(),setBounds()(“”)4java.awtƒFlowLayoutPanelAppletƒBorderLayoutWindowDialogFrameƒGridLayoutƒCardLayoutƒGridBagLayout•1•2ContainersetLayout()•3Containeradd()•SwingAbstractButtonaddActionListener()–6.7,P365:FlowLayoutDemo.java4——BorderLayoutBorderLayout5North,South,East,WestCenterBorderLayoutpublicBorderLayout()0publicBorderLayout(inthorizontalGap,intverticalGap)NorthSouthWestEastCenter6.8,P370:BorderLayoutDemo.java•–(1)–(2)4–(3)6.31•.4——GridLayoutGridLayoutBorderLayoutPanelPanel.GridLayoutpublicGridLayout()0publicGridLayout(introws,intcols)rowscolsrowscols0rows0colscols0rows0publicGridLayout(introws,intcols,inthorizontalGap,intverticalGap)6.9,P373:GridLayoutDemo.java4——CardLayoutCardLayoutCardLayoutƒpublicvoidshow(Containerparent,Stringname)ƒpublicvoidnext(Containerparent)ƒpublicvoidprevious(Containerparent)ƒpublicvoidfirst(Containerparent)ƒpublicvoidlast(Containerparent)ContainerCardLayout4——CardLayoutCardLayoutpublicCardLayout()0publicCardLayout(inthorizontalGap,intverticalGap)BorderLayoutGridLayoutCardLayoutadd(String,Component);4——GridBagLayoutGridBagLayoutAWTGridLayoutGridBagLayoutGridBagConstraints()GridBagLayout,.GridBagLayoutmyLayout=newGridBagLayout();4——GridBagLayoutGridBagConstraintsƒgridx,gridyƒgridwidth,gridheightƒfillƒipadx,ipadyƒinsetsƒarchorƒweightx,weighty4——GridBagLayoutGridBagLayoutGridBagConstraints//GridBagLayoutg=newGridBagLayout();GridBagConstraintsc=newGridBagConstraints();setLayout(g);Buttonb=newButton(“Test”);//bc.fill=…//c……g.setConstraints(b,c);/*cb*/add(b);4——GridBagLayoutGridBagLayoutGridBagConstraintsGridBagConstraintsGridBagWindow.java6.55JavaclassActionEventWindowEventJDK1.01.125——JDK1.0JDK1.0java.awt.Eventjava.lang.ObjectEventidif(Ev.id==ACTION_EVENT){…}5——JDK1.0JDK1.0“”HierarchicaleventmodelAWTComponentaction(Evente,Objectarg)handleEvent(Evente)AWTJDK1.0JDK1.0action()handleEvent()AWTactionJDK1.05—JDK1.1JDK1.1java.awt.eventAWTEventAWTEventAWTAWTjava.util.EventObjectjava.awt.event.AWTEventAWTEventAWTEventƒComponentEvent,ContainerEvent,WindowEvent,FocusEvent,KeyEvent,MouseEventHierarchyEvent,InputMethodEvent,InvocationEvent,ƒGUIActionEvent,AdjustmentEvent,ItemEvent,TextEvent•high-leveleventlow-leveleventsemanticevent•“”••AWTactionPerformed()JDK1.1[listener]“-”DelegationeventmodelActionEventWindowEvent“”“”ComponentaddXXXListener(ListenerTypelistener)ActionPerformed(ActionEvente)removeXXXListener(ListenerTypelistener)TestExitActionEventactionPerformed(ActionEvente)FrameButtonListenerXXXEventXXXListeneraddXXXListener(XXXListener)6.11P387ButtonEventTest.java•AWTSwingActionListener()•“”ActionaddActionListener()“”publicvoidaddActionListener(ActionListenerl){...}ActionListenerl“”“”“”.addActionListener();•ActionListenerEventListeneractionPerformed()publicinterfaceActionListenerextendsEventListener{publicvoidactionPerformed(ActionEvente);}ActionEventactionPerformed()••XXXListenerJDK1.1XXXAdapter6.66——……AWTGUIWindow.javaSwingGUIWindow2.javanewsetLayoutaddaddListenerj2sdk

1 / 35
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功