Archive for March, 2008

Make a web site - Chapter 12 Graphical User Interface Components: Part 1

Monday, March 3rd, 2008

Chapter 12 Graphical User Interface Components: Part 1 713 LayoutManagermethod layoutContainer recalculates the layout of its Container argument. The GridLayout layout manager divides the container into a grid of rows and columns. Components are added to a GridLayout starting at the top-left cell and proceeding from left to right until the row is full. Then the process continues from left to right on the next row of the grid, and so on. Container method validate recomputes the container s layout based on the current layout manager for the Container and the current set of displayed GUI components. Panels are created with class JPanel, which inherits from class JComponent. JPanels may have components, including other panels, added to them. TERMINOLOGY .giffile name extension dispatch an event .jpgfile name extension dragging listen for an event drop-down list Abstract Windowing Toolkit event AbstractButton class event driven ActionEvent class event handler ActionListener interface event ID actionPerformed method event listener adapter class event-listener interface add method of ButtonGroup EventListenerList class add method of class Container EventObject class addItemListener method FlowLayout class addKeyListenermethod FlowLayout.CENTER addListSelectionListenermethod FlowLayout.LEFT addMouseListenermethod FlowLayout.RIGHT addMouseMotionListenermethod focus assistive technologies FocusAdapter class BorderLayout class FocusListener interface BorderLayout.CENTER Font.BOLD BorderLayout.EAST Font.ITALIC BorderLayout.NORTH Font.PLAIN BorderLayout.SOUTH getActionCommandmethod BorderLayout.WEST getClickCountmethod button getIcon method button label getKeyChar method of KeyEvent ButtonGroup class getKeyCode method of KeyEvent centered getKeyModifiersText method check box getKeyText method of KeyEvent check box label getModifiers method of InputEvent command button getPassword method of JPasswordField Component class getSelectedIndex method of JComboBox ComponentAdapter class getSelectedIndex method of JList ComponentListener interface getSelectedValuesmethod of JList Container class getSourcemethod of ActionEvent ContainerAdapter class getStateChange method of ItemEvent ContainerListener interface getText method of JLabel control getX method of MouseEvent delegation event model getY method of MouseEvent Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01

712 Graphical User (Web hosting ecommerce) Interface Components: Part 1 Chapter

Sunday, March 2nd, 2008

712 Graphical User Interface Components: Part 1 Chapter 12 A MULTIPLE_INTERVAL_SELECTIONlist allows continuous range selection as described for a SINGLE_INTERVAL_SELECTION list and allows miscellaneous items to be selected by holding the Ctrl key while clicking each item to select. JList method setFixedCellHeight specifies the height in pixels of each item in a JList. Method setFixedCellWidth sets the width in pixels of a JList. Normally, an event generated by another GUI component (known as an external event) specifies when the multiple selections in a JList should be processed. JListmethod setListData sets the items displayed in a JList. Method getSelected- Valuesreturns the selected items as an array of Objects. Mouse events can be trapped for any GUI component that derives from java.awt.Component using MouseListeners and MouseMotionListeners. Each mouse event handling method takes as its argument a MouseEvent object containing information about the mouse event and the location where the event occurred. Methods addMouseListener and addMouseMotionListener are Component methods used to register mouse event listeners for an object of any class that extends Component. Many of the event-listener interfaces provide multiple methods. For each, there is a corresponding event-listener adapter class that provides a default implementation of every method in the interface. The programmer can extend the adapter class to inherit the default implementation of every method and simply override the method or methods needed for event handling in the program. MouseEvent method getClickCountreturns the number of mouse clicks. InputEventmethods isMetaDownand isAltDown are used to determine which mouse button the user clicked. KeyListeners handle key events that are generated when keys on the keyboard are pressed and released. A KeyListener must provide definitions for methods keyPressed, keyReleased and keyTyped, each of which receives a KeyEvent as its argument. Method keyPressed is called in response to pressing any key. Method keyTyped is called in response to pressing any key that is not an action key (i.e., an arrow key, Home, End, Page Up, Page Down, a function key, Num Lock, Print Screen, Scroll Lock, Caps Lock and Pause). Method keyReleased is called when the key is released after any keyPressedor keyTyped event. KeyEvent method getKeyCode gets the virtual key code of the key that was pressed. Class KeyEvent maintains a set of virtual key code constants that represent every key on the keyboard. KeyEventmethod getKeyText returns a String containing the name of the key that corresponds to its virtual key code argument. Method getKeyChar gets the Unicode value of the character typed. Method isActionKey determines if the key in the event was an action key. InputEvent method getModifiersdetermines if any modifier keys (such as Shift, Alt and Ctrl) were pressed when the key event occurred. KeyEventmethod getKeyModifiersText produces a string containing the names of the pressed modifier keys. Layout managers arrange GUI components on a container for presentation purposes. FlowLayout lays out components from left to right in the order in which they are added to the container. When the edge of the container is reached, components are continued on the next line. FlowLayoutmethod setAlignment changes the alignment for the FlowLayoutto Flow- Layout.LEFT, FlowLayout.CENTERor FlowLayout.RIGHT. The BorderLayoutlayout manager arranges components into five regions: North, South, East, West and Center. One component can be added to each region. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01

Hosting web - Chapter 12 Graphical User Interface Components: Part 1

Saturday, March 1st, 2008

Chapter 12 Graphical User Interface Components: Part 1 711 Every JComponent contains an object of class EventListenerList (package javax.swing.event) called listenerListin which all registered listeners are stored. Every JComponent supports several different event types, including mouse events, key events and others. When an event occurs, the event is dispatched only to the event listeners of the appropriate type. Each event type has a corresponding event-listener interface. When an event is generated by a user interaction with a component, the component is handed a unique event ID specifying the event type. The GUI component uses the event ID to decide the type of listener to which the event should be dispatched and the event handler method to call. A JButton generates an ActionEvent when the user clicks the button with the mouse. An AbstractButton can have a rollover Iconthat is displayed when the mouse is positioned over the button. The icon changes as the mouse moves in and out of the button s area on the screen. AbstractButton method setRolloverIcon specifies the image displayed on a button when the user positions the mouse over the button. The Swing GUI components contain three state button types JToggleButton, JCheckBox and JRadioButton that have on/off or true/false values. Classes JCheckBox and JRadio- Button are subclasses of JToggleButton. When the user clicks a JCheckBox, an ItemEvent is generated that can be handled by an ItemListener. ItemListeners must define method itemStateChanged. Item- Eventmethod getStateChange determines the state of a JToggleButton. JRadioButtons are similar to JCheckBoxes in that they have two states selected and not selected (also called deselected). JRadioButtons normally appear as a group in which only one radio button can be selected at a time. The logical relationship between radio buttons is maintained by a ButtonGroupobject. The JRadioButtonconstructor supplies the label that appears to the right of the JRadioButton by default and the initial state of the JRadioButton. A true second argument indicates that the JRadioButton should appear selected when it is displayed. JRadioButtons generate ItemEvents when they are clicked. ButtonGroupmethod add associates a JRadioButtonwith a ButtonGroup. If more than one selected JRadioButton object is added to the group, the last selected JRadioButton added will be selected when the GUI is displayed. A JComboBox (sometimes called a drop-down list) provides a list of items from which the user can make a selection. JComboBoxes generate ItemEvents. A numeric index keeps track of the ordering of items in a JComboBox. The first item is added at index 0, the next item is added at index 1 and so forth. The first item added to a JComboBox appears as the currently selected item when the JComboBox is displayed. JComboBoxmethod getSelectedIndex returns the index number of the selected item. A JList displays a series of items from which the user may select one or more items. Class JList supports single- and multiple-selection lists. When an item is clicked in a JList, a ListSelectionEvent occurs. JListmethod setVisibleRowCount determines the number of items that are visible in the list. Method setSelectionMode specifies the selection mode for the list. Class JListdoes not automatically provide a scrollbar if there are more items in the list than the number of visible rows. A JScrollPane object is used to provide the automatic scrolling capability for a JList. A SINGLE_INTERVAL_SELECTION list allows selection of a contiguous range of items by clicking the first item, then holding the Shift key while clicking the last item to select in the range. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01