Page 2 :
1.4 Use of Layout Managers:, , , CardLayout:, , , , The CardLayout class is unique among the other layout, managers in that it stores several different layouts., , , , Each layout can be thought of as being on a separate, index card in a deck that can be shuffled so that any card, is on top at a given time., , DJ Sir
Page 3 :
1.4 Use of Layout Managers:, , , CardLayout:, , , , This can be useful for user interfaces with optional, components that can be dynamically enabled and, disabled upon user input., , , , You can prepare the other layouts and have them hidden,, ready to be activated when needed., , DJ Sir
Page 4 :
1.4 Use of Layout Managers:, , , CardLayout:, , , , The CardLayout class manages the components in such a, manner that only one component is visible at a time., , , , It treats each component as a card that is why it is known, as CardLayout., , DJ Sir
Page 5 :
1.4 Use of Layout Managers:, , , CardLayout:Constructors, , , , CardLayout() - creates a card layout with zero, horizontal and vertical gap., , , , CardLayout(int hGap, int vGap) - creates a card, layout with the given horizontal and vertical gap., , DJ Sir
Page 6 :
1.4 Use of Layout Managers:, , , CardLayout:, , , , Use of a card layout requires a bit more work than the, other layouts. The cards are typically held in an object of, type Panel., , , , This panel must have CardLayout selected as its layout, manager., , DJ Sir
Page 7 :
1.4 Use of Layout Managers:, , , CardLayout:, , , , The cards that form the deck are also typically objects of, type Panel., , , , Thus, you must create a panel that contains the deck and, a panel for each card in the deck., , , , Next, you add to the appropriate panel the components, that form each card., , DJ Sir
Page 8 :
1.4 Use of Layout Managers:, , , CardLayout:, , , , You then add these panels to the panel for which, CardLayout is the layout manager., , , , Finally, you add this panel to the main applet of Frame, panel., , , , Once these steps are complete, you must provide some, way for the user to select between cards., , DJ Sir
Page 9 :
1.4 Use of Layout Managers:, , , CardLayout:, , , , One common approach is to include one push button for, each card in the deck., , , , When card panels are added to a panel, they are usually, given a name., , DJ Sir
Page 10 :
1.4 Use of Layout Managers:, , , CardLayout:, , , , Thus, most of the time, you will use this form of add( ), when adding cards to a panel:, void add(Component panelObj, Object name), , , , Here, name is a string that specifies the name of the card, whose panel is specified by panelObj., , DJ Sir
Page 11 :
1.4 Use of Layout Managers:, , , CardLayout:Methods, , , , After you have created a deck, your program activates a, card by calling one of the following methods defined by, CardLayout:, , , , public void next(Container parent) - It is used to flip, to the next card of the given container., , DJ Sir
Page 12 :
1.4 Use of Layout Managers:, , , CardLayout:Methods, , , , public void previous(Container parent) - It is used to, flip to the previous card of the given container., , , , public void first(Container parent) - It is used to flip to, the first card of the given container., , DJ Sir
Page 13 :
1.4 Use of Layout Managers:, , , CardLayout:Methods, , , , public void last(Container parent) - It is used to flip to, the last card of the given container., , , , public void show(Container parent, String name) - It, is used to flip to the specified card with the given name. ., , DJ Sir
Page 14 :
1.4 Use of Layout Managers:, , , CardLayout:, , , , Here, deck is a reference to the container (usually a, panel) that holds the cards, and cardName is the name of, a card., , , , Calling first( ) causes the first card in the deck to be, shown., , DJ Sir
Page 15 :
1.4 Use of Layout Managers:, , , CardLayout:, , , , To show the last card, call last( )., , , , To show the next card, call next( )., , , , To show the previous card, call previous( )., , , , Both next( ) and previous( ) automatically cycle back to, the top or bottom of the deck, respectively., , DJ Sir
Page 16 :
1.4 Use of Layout Managers:, , , CardLayout:, , , , The show( ) method displays the card whose name is, passed in cardName., , DJ Sir
Page 17 :
1.4 Use of Layout Managers:, , , CardLayout :Example, X, , ˗, , First, , DJ Sir, , Previous, , Next, , Last