FileDocCategorySizeDatePackage
Card.javaAPI DocExample997Mon May 01 14:41:58 BST 2000None

Card.java

//file: Card.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Card extends JPanel {
  CardLayout cards = new CardLayout(  );

  public Card(  ) {
    setLayout(cards);
    ActionListener listener = new ActionListener(  ) {
      public void actionPerformed(ActionEvent e) {
        cards.next(Card.this);
      }
    };
    JButton button;
    button = new JButton("one");
    button.addActionListener(listener);
    add(button, "one");
    button = new JButton("two");
    button.addActionListener(listener);
    add(button, "two");
    button = new JButton("three");
    button.addActionListener(listener);
    add(button, "three");
  }

  public static void main(String[] args) {
    JFrame f = new JFrame("Card");
    f.addWindowListener(new WindowAdapter(  ) {
      public void windowClosing(WindowEvent e) { System.exit(0); }
    });
    f.setSize(200, 200);
    f.setLocation(200, 200);
    f.setContentPane(new Card(  ));
    f.setVisible(true);
  }
}