examples
Class CardExample

java.lang.Object
  extended by examples.CardExample

public class CardExample
extends java.lang.Object

An example to illustrate the use of the class CardCell for the GUI shown below.

The GUI contains a CardCell at the bottom. The CardCell has three JLabel objects as its elements, with their display texts being Mutable Component 1, Mutable Component 2, and Mutable Component 3. When the user clicks the button with text Show Component 2, the label with the text Mutable Component 2 in the card is displayed. The the other buttons are associated with the labels in a similar fashion.

public class CardExample
{
        public static String MUTABLECELLNAME="Mutable Component ";
        public static void createGUI()
        {
                // Create the card with the three labels.
                CardCell card=new CardCell();
                for(int i=1;i<=3;i++)
                {
                        String name=MUTABLECELLNAME+i;
                        card.add(name,namedPanel(name));
                }
                JFrame f=new JFrame();
                // The top level cell.
                ButtonGroup bg=new ButtonGroup();
                // Create the three buttons with appropriate action listeners.
                JRadioButton buttons[]=new JRadioButton[3];
                for(int i=1;i<=3;i++)
                {
                        JRadioButton button=new JRadioButton("Show Component "+i);
                        button.addActionListener(
                                        new ButtonAction(card,i));
                        bg.add(button);
                        buttons[i-1]=button;
                }

                // Create the layout.
                column(center,center,
                       buttons[0],buttons[1],
                       buttons[2],card).createLayout(f.getContentPane());

                f.pack();
                f.show();
        }
        //The action listener for the radio buttons.
        public static class ButtonAction implements ActionListener
        {
                private CardCell card;
                private int index;
                public ButtonAction(CardCell card, int index)
                {
                        this.card=card;
                        this.index=index;
                }
                //Show the associated label in the card.
                public void actionPerformed(ActionEvent e)
                {
                        card.showCell(MUTABLECELLNAME+index);
                }
        }
        public static class GUICreator implements Runnable
        {
                public void run()
                {
                        createGUI();
                }
        }
        public static JComponent namedPanel(String name)
        {
                JLabel j=new JLabel(name,SwingConstants.CENTER);
                j.setMaximumSize(new Dimension(Cell.MAX,Cell.MAX));     
                j.setOpaque(true);
                j.setBackground(Color.blue);
                return j;
        }
        public static void main(String[] args)
        {
                SwingUtilities.invokeLater( new GUICreator());

        }
}


Nested Class Summary
static class CardExample.ButtonAction
           
static class CardExample.GUICreator
           
 
Field Summary
static java.lang.String MUTABLECELLNAME
           
 
Constructor Summary
CardExample()
           
 
Method Summary
static void createGUI()
           
static void main(java.lang.String[] args)
           
static javax.swing.JComponent namedPanel(java.lang.String name)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MUTABLECELLNAME

public static java.lang.String MUTABLECELLNAME
Constructor Detail

CardExample

public CardExample()
Method Detail

createGUI

public static void createGUI()

namedPanel

public static javax.swing.JComponent namedPanel(java.lang.String name)

main

public static void main(java.lang.String[] args)