Class Deck

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class Deck extends JPanel
A class to providing a panel with CardLayout. Components can be added to the panel, although only one will be visible at a time. Although CardLayout requires components to be selected by name, this class allows components to be selected by reference.
See Also:
  • Constructor Details

    • Deck

      public Deck()
      Create a Deck panel.
    • Deck

      public Deck(String name)
      Create a Deck panel with a given name.
      Parameters:
      name - the name for the panel
    • Deck

      public Deck(String name, Component... comps)
      Create a Deck panel with a given name and set of components.
      Parameters:
      name - the name for the panel
      comps - the components to be added into the panel
  • Method Details

    • setLayout

      public void setLayout(LayoutManager lm)
      Overrides:
      setLayout in class Container
    • add

      public Component add(Component comp)
      Add a component to the panel. If the component does not have a name a default name will be set. The name of the component should not be changed after it has been added to the deck.
      Overrides:
      add in class Container
      Parameters:
      comp - The component to be added.
      Returns:
      The component that was added (comp).
    • add

      public void add(Component comp, Object x)
      Add a component to the panel. The constraints are ignored.
      Overrides:
      add in class Container
      Parameters:
      comp - The component to be added
      x - Ignored
    • getCurrentCard

      public Component getCurrentCard()
      Get the component that is currently visible in the deck.
      Returns:
      the component that is currently visible in the deck.
    • show

      public void show(Component comp)
      Make a component visible in the deck. If different, the previously visible component will be hidden.
      Parameters:
      comp - The component to be made visible. It must previously have been added to the deck.