您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 企业文化 > 59Java第06章--1(AWT与Swing)
JavaJavapenggang@mail.hust.edu.cn12AWT(AbstractWindowToolkit)3Swing4566.11…/1“”IconWindowMenu/MenuItemButtonLabelList………1“”AbstractWindowsToolsKitAWT2SwingJavaGUI“lookandfeel”JavaAWTAWTpeerGUI“”heavyweightcomponentsAWTOpaquerectangularregion“”1997SunNetscapeJFCJavaFoundationClassesJava2JDK1.2AWTSwingJava2DAPIJFCSwinglightweightcomponentsAWTnon-opaqueSwingAWTAWTAWTSwingSwingSwingAWTdelegationeventmodelSwingAWTSwingAWTImageColorFontToolkitLayoutManagerSwingSwingJWindowJFrameJDialogJAppletAWTWindowFrameDialogApplet4SwingAWTComponentContainerComponentSwingAWTComponentAWTButtonLabelTextField“”SwingJJButtonJLabelJTextFieldJavaSwing6.2AWTAWT2AWT(AbstractWindowToolkit)GraphicalUserInterfaceGUIJavaJavaJavaFoundationClassesJFCGUIAPIAWTJavaJFCSwingAWT()2DAPIAPI……2AWT(AbstractWindowToolkit)“”AWTFrameFrameButtonLabelTextFieldFramejava.awtjava.awt.FrameMyFirsrFrame.java(6.1,P314)MianWindow.java(6.2,P318)•Frame;•–,paint().•add()•main()“mf.setVisible(true);”•thisthisadd();•FramePanelCanvasadd().add();•Frame•••“”TimerCnavas.java(6.3,P323)ClockFrame.java(6.3,P327):P329-P3376.3SwingSwing“”1997SunNetscapeJFCJavaFoundationClassesJava2JDK1.2AWTSwingJava2DAPIJFCSwingGUIAWT“Model-View-Controller”SwingGUIJava“”SwinglightweightcomponentsAWTnon-opaqueModel-View-Controller•GUI–•“”“”;–•;–••Model–View-ControllerMVC3•••model•SwingJButtonJButtonjavax.swing.AbstractButtonisSelected()–publicbooleanisSelected(){...}–truefalse•javax.swingModeljavax.swing–publicinterfaceButtonModelextendsItemSelectable{...}•JButtonAbstractButton–JButtonb=newJButton();BttMdlbtMdl()••viewpaint()MVC•••controller•JFCJPanelp=newJPanel();//JButtonb=newJButton();//p.add(b);//“”bp•JButtonadd()JavaJFCJComponentpaint()Graphics•JComponentJComponentpaint()3•protectedvoidpaintComponent(Graphicsg){...}•protectedvoidpaintBorder(Graphicsg){...}•protectedvoidpaintChildren(Graphicsg){...}•MVC–“”–“”“”JComponentpaint()SwingJComponentjava.awt.ContainerJComponentComponentContainerJFrame•JFrame•JFramejava.awt.FrameJFC/SwingrootPanelayeredPanecontentPaneglassPane4JFrame•layeredPanemenuBaroptionalmenuBarcontentPaneSwing•SwingJFrameJDialogJWindowJApplet4AWT•JRootPanerootPaneSwingrootPanerootPane•rootPaneJRootPaneJFrameJFramepublicclassJFrameextendsFrameimplementsWindowConstants,Accessible,RootPaneContainer{...protectedJRootPanerootPane;...}•3rootPaneJRootPanepublicclassJRootPaneextendsJComponentimplementsAccessible{...protectedJLayeredPanelayeredPane;//layeredPaneJLayeredPaneprotectedContainercontentPane;//contentPaneContainerprotectedComponentglassPane;//glassPaneComponentprotectedJMenuBarmenuBar;//menuBarJMenuBar...}•JFrame3WindowConstantsAccessibleRootPaneContainer•WindowConstants36.4(P348)–DO_NOTHING_ON_CLOSE//–HIDE_ON_CLOSE//–DISPOSE_ON_CLOSE//•Accessiblejavax.accessibilityAccessiblepublicAccessibleContextgetAccessibleContext(){...}•AccessibleContext•RootPaneContainergetContentPane()JRootPanepublicContainergetContentPane(){returngetRootPane().getContentPane();}•getRootPane()JDialogJFrameJWindowJAppletpublicJRootPanegetRootPane(){...}•contentPane•SwingGUIcontentPaneJFrameJAppletSwinggetContentPane()publicContainergetContentPane(){...}//•ContainerSwingcontentPaneContainerContainercontentPane=getContentPane();•JFrameframeJFrameframe=newJFrame();ContainercontentPane=frame.getContentPane();JButtonokButton=newJButton(“”);contentPane.add(okButton);//okButtonframecontentPaneSwing•6.5,P348(JComponentTest.java)•1SwingJFrameJAppletJDialog(MyMainWindow)JFrame;•2buildMW()JFramegetContentPane()•3•4,(JButton),(JLabel),(JTextField)•5java.awt.Containeradd()•6main();,;setVisible(true);•MyMainWindowJFrame•ToolkitgetScreenSize()screenSizeDimensionDimensionscreenSize,selfBounds;Toolkittoolkit=Toolkit.getDefaultToolkit();/*getDefaultToolkit()*/screenSize=toolkit.getScreenSize();//•selfBounds=getSize();//——12AWT(AbstractWindowToolkit)3Swing456
本文标题:59Java第06章--1(AWT与Swing)
链接地址:https://www.777doc.com/doc-5361439 .html