CardLayout Class Assignment Help

Assignment Help: >> Layout Managers - CardLayout Class

CardLayout Class:

An AWT CardLayout class is unique. Relatively than placing multiple controls in a Container object, this layout shows the controls one at a time (much like the familiar deck of cards in the ubiquitous Solitaire game). Controls which are displayed might, actually, be composite controls. Thus, you can present whole different sets of controls to the user in a manner same to the tabbed dialog boxes in which Microsoft Windows uses. Figure displays an applet along with five buttons laid out in a CardLayout fashion.

The card applet creates a CardLayout along with five buttons:

import java.awt.*;

public class card extends java.applet.Applet {

CardLayout layout ;

public void init() {

layout = new CardLayout() ;

setLayout( layout ) ;

add( new Button( "First" ) ) ;

add( new Button( "Second" ) ) ;

add( new Button( "Third" ) ) ;

add( new Button( "Fourth" ) ) ;

add( new Button( "Fifth" ) ) ;

}

public boolean action( Event evt, Object arg ) {

if ( evt.target instanceof Button ) {

layout.next(this) ;

return true ;

}

return false ;

}

}

1186_cardlayout class.png

A card applet places five Button objects in a CardLayout. Whenever any button is pressed, an action () method calls the CardLayout's next () method to show the next card in order. This layout also permits you to label the several controls which are added.

An add() method takes an optional String parameter which labels the controls you add. The given call adds a Button labeled my button with the label Push Me:

add( "my button", new Button( "Push Me" ) ;

At one the controls have labels, you can show them without having to displays them in sequence, without calling the layout's next() method. For show my button, simply call the layout's show() method:

show( this, "my button" ) ;

A show() method show a specified control; the next() method shows the next control in order. A CardLayout class gives the following functions to navigate the controls in the layout:

  • first( Container )
  • last( Container )
  • next( Container )
  • previous( Container )
  • show( Container, String )

 

All these navigational functions will take a reference to a Container object as a parameter. An show() method takes a String containing the label provide to the control whenever it was added.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd