FileDocCategorySizeDatePackage
CardWindow.javaAPI DocExample1960Tue Dec 12 18:59:00 GMT 2000None

CardWindow

public class CardWindow extends JFrame implements ItemListener

Fields Summary
boolean
inAnApplet
JPanel
cards
static final String
BUTTONPANEL
static final String
TEXTPANEL
Constructors Summary
public CardWindow()


      
        Container contentPane = getContentPane();

        //Put the JComboBox in a JPanel to get a nicer look.
        String comboBoxItems[] = { BUTTONPANEL, TEXTPANEL };
        JPanel cbp = new JPanel();
        JComboBox c = new JComboBox(comboBoxItems);
        c.setEditable(false);
        c.addItemListener(this);
        cbp.add(c);

        //Use the default layout manager, BorderLayout
        contentPane.add(cbp, BorderLayout.NORTH);

        cards = new JPanel();
        cards.setLayout(new CardLayout());
   
        JPanel p1 = new JPanel();
        p1.add(new JButton("Button 1"));
        p1.add(new JButton("Button 2"));
        p1.add(new JButton("Button 3"));

        JPanel p2 = new JPanel();
        p2.add(new JTextField("TextField", 20));

        cards.add(p1, BUTTONPANEL);
        cards.add(p2, TEXTPANEL);
        contentPane.add(cards, BorderLayout.CENTER);
        
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                if (inAnApplet) {
                    dispose();
                } else {
                    System.exit(0);
                }
            }
        });
    
Methods Summary
public voiditemStateChanged(java.awt.event.ItemEvent evt)

        CardLayout cl = (CardLayout)(cards.getLayout());
        cl.show(cards, (String)evt.getItem());
    
public static voidmain(java.lang.String[] args)

        CardWindow window = new CardWindow();
        window.inAnApplet = false;

        window.setTitle("CardLayout");
        window.pack();
        window.setVisible(true);