Web server setup - 770 Graphical User Interface Components: Part 2 Chapter
Monday, April 30th, 2007770 Graphical User Interface Components: Part 2 Chapter 13 ible GUI component that can be used between fixed-size GUI components to occupy additional space. Normally, extra space appears to the right of the last horizontal GUI component or below the last vertical GUI component in a BoxLayout. Glue allows the extra space to be placed between GUI components. Class Box also defines method createVerticalGlue for vertical BoxLayouts. The for structure at lines 47 51 adds three JButtons to boxes[3] (a vertical Box). Before adding each button, lines 48 49 add a rigid area to the container with static method createRigidArea of class Box. A rigid area is an invisible GUI component that always has a fixed pixel width and height. The argument to method createRigidAreais a Dimension object that specifies the width and height of the rigid area. Lines 54 56 create a JPanel object and set its layout in the conventional manner, using Container method setLayout. The BoxLayout constructor receives a reference to the container for which it controls the layout and a constant indicating whether the layout is horizontal (BoxLayout.X_AXIS) or vertical (BoxLayout.Y_AXIS). The for structure at lines 58 61 adds three JButtons to panel.Before adding each button, line 59 adds a glue component to the container with static method create- Glue of class Box. This component expands or contracts based on the size of the Box. The Box containers and the JPanel are attached to the content pane s Border- Layout at lines 64 68. Try executing the application. When the window appears, resize the window to see how the glue components, strut components and rigid area affect the layout in each container. 13.14 CardLayout Layout Manager The CardLayout layout manager arranges components into a deck of cards where only the top card is visible. Any card in the deck can be placed at the top of the deck at any time by using methods of class CardLayout. Each card is usually a container, such as a panel, and each card can use any layout manager. Class CardLayout inherits from Object and implements the LayoutManager2 interface. The program of Fig. 13.16 creates five panels. JPaneldeck uses the CardLayout layout manager to control the card that is displayed. JPanels card1, card2 and card3 are the individual cards in deck. JPanel buttons contains four buttons (with labels First card, Next card, Previous card and Last card) that enable the user to manipulate the deck. When the user clicks the First card button, the first card in deck (i.e., card1) is displayed. When the user clicks the Last card button, the last card (i.e., card3) in deck is displayed. Each time the user clicks the Previous card button, the previous card in deck is displayed. Each time the user clicks the Next card button, the next card in deck is displayed. Clicking the Previous card button or the Next card button repeatedly allows the user to cycle through the deck of cards. Application class CardDeck implements ActionListener, so the action events generated by the JButtons on JPanel buttons are handled by the application in its actionPerformed method. Class CardDeck declares a reference of type CardLayout called cardManager (line 13). This reference is used to invoke CardLayout methods that manipulate the cards in the deck.
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision ecommerce web hosting services