java语言程序设计-基础篇--第八版--英文课件(第12章)

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

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

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

资源描述

Liang,IntroductiontoJavaProgramming,EighthEdition,(c)2011PearsonEducation,Inc.Allrightsreserved.0132130807Chapter12GUIBasics1Liang,IntroductiontoJavaProgramming,EighthEdition,(c)2011PearsonEducation,Inc.Allrightsreserved.0132130807MotivationsThedesignoftheAPIforJavaGUIprogrammingisanexcellentexampleofhowtheobject-orientedprincipleisapplied.Inthechaptersthatfollow,youwilllearntheframeworkofJavaGUIAPIandusetheGUIcomponentstodevelopuser-friendlyinterfacesforapplicationsandapplets.2Liang,IntroductiontoJavaProgramming,EighthEdition,(c)2011PearsonEducation,Inc.Allrightsreserved.0132130807ObjectivesTodistinguishbetweenSwingandAWT(§12.2).TodescribetheJavaGUIAPIhierarchy(§12.3).Tocreateuserinterfacesusingframes,panels,andsimpleGUIcomponents(§12.4).Tounderstandtheroleoflayoutmanagers(§12.5).TousetheFlowLayout,GridLayout,andBorderLayoutmanagerstolayoutcomponentsinacontainer(§12.5).TouseJPanelassubcontainers(§12.7).TospecifycolorsandfontsusingtheColorandFontclasses(§§12.7-12.8).Toapplycommonfeaturessuchasborders,tooltips,fonts,andcolorsonSwingcomponents(§12.9).Touseborderstovisuallygroupuser-interfacecomponents(§12.9).TocreateimageiconsusingtheImageIconclass(§12.10).3Liang,IntroductiontoJavaProgramming,EighthEdition,(c)2011PearsonEducation,Inc.Allrightsreserved.0132130807CreatingGUIObjects//CreateabuttonwithtextOKJButtonjbtOK=newJButton(OK);//CreatealabelwithtextEnteryourname:JLabeljlblName=newJLabel(Enteryourname:);//CreateatextfieldwithtextTypeNameHereJTextFieldjtfName=newJTextField(TypeNameHere);//CreateacheckboxwithtextboldJCheckBoxjchkBold=newJCheckBox(Bold);//CreatearadiobuttonwithtextredJRadioButtonjrbRed=newJRadioButton(Red);//Createacomboboxwithchoicesred,green,andblueJComboBoxjcboColor=newJComboBox(newString[]{Red,Green,Blue});4ButtonLabelTextfieldCheckBoxRadioButtonComboBoxLiang,IntroductiontoJavaProgramming,EighthEdition,(c)2011PearsonEducation,Inc.Allrightsreserved.0132130807Swingvs.AWTSowhydotheGUIcomponentclasseshaveaprefixJ?InsteadofJButton,whynotnameitsimplyButton?Infact,thereisaclassalreadynamedButtoninthejava.awtpackage.WhenJavawasintroduced,theGUIclasseswerebundledinalibraryknownastheAbstractWindowsToolkit(AWT).ForeveryplatformonwhichJavaruns,theAWTcomponentsareautomaticallymappedtotheplatform-specificcomponentsthroughtheirrespectiveagents,knownaspeers.AWTisfinefordevelopingsimplegraphicaluserinterfaces,butnotfordevelopingcomprehensiveGUIprojects.Besides,AWTispronetoplatform-specificbugsbecauseitspeer-basedapproachreliesheavilyontheunderlyingplatform.WiththereleaseofJava2,theAWTuser-interfacecomponentswerereplacedbyamorerobust,versatile,andflexiblelibraryknownasSwingcomponents.SwingcomponentsarepainteddirectlyoncanvasesusingJavacode,exceptforcomponentsthataresubclassesofjava.awt.Windoworjava.awt.Panel,whichmustbedrawnusingnativeGUIonaspecificplatform.SwingcomponentsarelessdependentonthetargetplatformanduselessofthenativeGUIresource.Forthisreason,Swingcomponentsthatdon’trelyonnativeGUIarereferredtoaslightweightcomponents,andAWTcomponentsarereferredtoasheavyweightcomponents.5Liang,IntroductiontoJavaProgramming,EighthEdition,(c)2011PearsonEducation,Inc.Allrightsreserved.0132130807GUIClassHierarchy(Swing)6DimensionFontFontMetricsComponentGraphicsObjectColorContainerPanelAppletFrameDialogWindowJComponentJAppletJFrameJDialogSwingComponentsinthejavax.swingpackageLightweightHeavyweightClassesinthejava.awtpackage1LayoutManager*Liang,IntroductiontoJavaProgramming,EighthEdition,(c)2011PearsonEducation,Inc.Allrightsreserved.0132130807ContainerClasses7DimensionFontFontMetricsComponentGraphicsObjectColorContainerPanelAppletFrameDialogWindowJComponentJAppletJFrameJDialogSwingComponentsinthejavax.swingpackageLightweightHeavyweightClassesinthejava.awtpackage1LayoutManager*JPanelContainerclassescancontainotherGUIcomponents.Liang,IntroductiontoJavaProgramming,EighthEdition,(c)2011PearsonEducation,Inc.Allrightsreserved.0132130807GUIHelperClasses8DimensionFontFontMetricsComponentGraphicsObjectColorContainerPanelAppletFrameDialogWindowJComponentJAppletJFrameJDialogSwingComponentsinthejavax.swingpackageLightweightHeavyweightClassesinthejava.awtpackage1LayoutManager*JPanelThehelperclassesarenotsubclassesofComponent.TheyareusedtodescribethepropertiesofGUIcomponentssuchasgraphicscontext,colors,fonts,anddimension.Liang,IntroductiontoJavaProgramming,EighthEdition,(c)2011PearsonEducation,Inc.Allrightsreserved.0132130807SwingGUIComponents9JMenuItemJCheckBoxMenuItemAbstractButtonJComponentJMenuJRadioButtonMenuItemJToggleButtonJCheckBoxJRadioButtonJComboBoxJInternalFrameJLayeredPaneJListJMenuBarJOptionPaneJPopupMenuJProgressBarJFileChooserJScrollBarJScrollPaneJSeparatorJSplitPaneJSliderJTabbedPaneJTableJTableHeaderJTextFieldJTextComponentJTextAreaJToolBarJToolTipJTreeJRootPaneJPanelJPasswordFieldJColorChooserJLabelJEditorPaneJSpinnerJButtonLiang,IntroductiontoJavaProgramming,EighthEdition,(c)2011PearsonEducation,Inc.Allrightsreserved.0132130807ComponentsCoveredintheBriefVersion10JMenuItemJCheckBoxMenuItemAbstractButtonJC

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

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

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

×
保存成功