JavaGuiJavaLecture11.pdf 英文原版
Java Gui – Java Lecture 11Abstract window ToolkitThe java. awt package was the primaryrepository for classes that are used to create aGUI in java but many of the classes it defineshave been superseded in Java 2 by javax. swingHowever the Swing classes are generallyderived from, and depend on, fundamentalclasses within java. awt, so these cant beignoredhttp:/freepdf-books.comGUI Class Hierarchy(Swing)DimensionClasses in the java. awtLayoutmanagerpackaHeavy weightFontFontmetricsobjectColorPanelAppletJAppletGraphicsComponentContainerWindowFrameJFrameDialogJDialogComponentSwing componentsin the javax. swing packageLightweighthttp://freepdf-books.comContainer classesDimensionClasses in the java. awtLayout managerpackageHeavyweightFontFontMetricsObjectColorPanelappletJAppletGraphicsComponentContainerWindowFrameameDialoalogDIalalog甲学Container classes can containJComponentJPanelg componentsin the javax. swing packageother GUI componentsLightweight5http:/freepdf-books.comSwing GUI ComponentsJCheck BoxMenultemMEnuitemJMenuAbstract ButtonJButtonJRadio Button menuitemJToggleButtonI Check BoxRAdio Button/ componentEDitor PaneJTextcomponentJTextFieldIPasswordFieldJTextareaJLabeJListJComboBoxJPanelJOption Pane JScrollBarliderJTabbedPaneJSplitPane JLayeredPane JSeparator JScrollPaneJRootpaneJToolBar」 MenuBar[ I PopupMenu「 File Chooser| ColorChlooserTOoltIpJTree Table| jInternalFramejProgressBar spinnerhttp:/freepdf-books.comComponents)A component represents a graphical entity ofone kind or another that can be displayed onscreenall container and visual components inheritfrom java. awt. Component)Key Classes: Window, JFrame, JDialogJApplet etchttp:/freepdf-books.comcHinEnter the password:.eeeeeolv Glasses FG0_Middle buttonPAssword FieldHairJButtonTeethCHeckbOxFrames Per SecondA Menu Another MenuMartha Washington102030A text-only menu itemAlt- 1Abigail AdamsBoth text and iconMartha RandolphJSliderDolley MadisonElizabeth monroeo A radio button menu itemLouisa AdamsFrameDemo□回囟Another oned A check box menu itemJList口 Another oneA submenuJFrameJMenuAn Inane QuestionDate07/2006区SPinner?Would you like green eggs and ham?JAppletYesNoJDialoghttp:/freepdf-books.comCreating GUl Objects// Create a button with text OKJbutton jbtoK new JButton(OK )// Create a label with text "Enter your name:Jlabel jblIName new JLabel( Enter your name: )LabeTextCheck Radiofield BoxButtoDisplay GUI ConponentsButtonOK Enter your name: Type Name Here|口Bod○ RedRedRedGreenBlue// Create a text field with text Type Name HereComboJTextField jtfName new JTextField( type Name here)Box// Create a check box with text boldJCheck Box jchk Bold new JCheck Box( Bold");/ Create a radio button with text redJRadioButton jrbRed new RAdiobUtton Red");// Create a combo box with choices red, green, and blueJComboBox jcboColor new JComboBox(new String[If RedGreen","Blue"])9http:/freepdf-books.comFramesframe is a window that is not contained inside anotherwindow, frame is the basis to contain other user interfacecomponents in Java GuI applicationsThe jframe class can be used to create windowsFor Swing GUI programS, use JFrame class to createwidows10http:/freepdf-books.com
用户评论