CardLayout
The CardLayout manager displays only one Component at a time. Each Component, or card, fills the display area of the entire Container. The cards are referred to by a programmer-defined string that is stored in a HashTable by CardLayout. Cards can be “brought to the front” by calling method show with the string for the card’s name or by calling method next repeatedly.
Corrsponding source code:
import java.awt.*;
import java.applet.Applet;
public class CardLayoutTest extends Applet {
CardLayout layout;
public void init() {
layout = new CardLayout();
setLayout(layout);
add("intro", new Label("Click the mouse to flip cards"));
add("Bob", new Label("A description of Bob"));
add("Jane", new Label("A description of Jane"));
layout.show(this, "intro"); // show first card
}
// upon any keyDown, switch "cards"
public boolean mouseDown(Event e, int x, int y) {
// show a card with 'this' as the enclosing container.
layout.next(this);
return true;
}
}
See also How to Use CardLayout.
|