692 Graphical User Interface Components: Part 1 Chapter (Hp web site)
692 Graphical User Interface Components: Part 1 Chapter 12 taining the name of the key that was pressed. For a complete list of virtual key constants, see the on-line documentation for class KeyEvent (package java.awt.event). Method keyTyped(lines 51 55) uses KeyEventmethod getKeyCharto get the Unicode value of the character typed. All three event handling methods finish by calling method setLines2and3 (lines 58 72) and passing it the KeyEvent object. This method uses KeyEvent method isActionKey to determine if the key in the event was an action key. Also, InputEventmethod getModifiersis called to determine if any modifier keys (such as Shift, Alt and Ctrl) were pressed when the key event occurred. The result of this method is passed to KeyEventmethod getKeyModifiersText, which produces a string containing the names of the pressed modifier keys. [Note: If you need to test for a specific key on the keyboard, class KeyEventprovides a key constant for every key on the keyboard. These constants can be used from the key event handlers to determine if a particular key was pressed. Also, to determine whether the Alt, Ctrl, Meta and Shift keys are pressed individually, InputEvent methods isAlt- Down, isControlDown, isMetaDown and isShiftDown each return a boolean indicating if the particular key was pressed during the key event.] 12.14 Layout Managers Layout managers are provided to arrange GUI components on a container for presentation purposes. The layout managers provide basic layout capabilities that are easier to use than determining the exact position and size of every GUI component. This enables the programmer to concentrate on the basic look and feel and lets the layout managers process most of the layout details. Look-and-Feel Observation 12.9 Most Java programming environments provide GUI design tools that help a programmer graphically design a GUI, then automatically write Java code to create the GUI. Some GUI designers also allow the programmer to use the layout managers described here and in Chapter 13. Figure 12.23 summarizes the layout managers presented in this chapter. Other layout managers are discussed in Chapter 13. Layout manager Description FlowLayout Default for java.awt.Applet, java.awt.Paneland javax.swing.JPanel. Places components sequentially (left to right) in the order they were added. It is also possible to specify the order of the components using the Containermethod addthat takes a Componentand an integer index position as arguments. BorderLayout Default for the content panes of JFrames (and other windows) and JApplets. Arranges the components into five areas: North, South, East, West and Center. GridLayout Arranges the components into rows and columns. Fig. 12.23 Layout managers. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01