| Cards.java |

    1
    2 import org.swixml.SwingEngine;
    3
    4 import javax.swing.*;
    5 import java.awt.*;
    6 import java.awt.event.ActionEvent;
    7
    8 /**
    9  * The <code>Cards</code> class shows an example for the usage of a CardLayout.
    10 *
    11 * @author <a href="mailto:wolf@paulus.com">Wolf Paulus</a>
    12 * @version $Revision: 1.1 $
    13 *
    14 * @since swixml #109
    15 */
    16public class Cards {
    17
    18  private static final String DESCRIPTOR = "xml/cards.xml";
    19  private SwingEngine swix = new SwingEngine( this );
    20
    21  /** panel with a CardLayout */
    22  public JPanel pnl;
    23
    24  private Cards() throws Exception {
    25    swix.render( Cards.DESCRIPTOR ).setVisible( true );
    26    this.showAction.actionPerformed( null );
    27  }
    28
    29  /** shows the next card */
    30  public Action nextAction = new AbstractAction() {
    31    public void actionPerformed( ActionEvent e ) {
    32      CardLayout cl = (CardLayout) ( pnl.getLayout() );
    33      cl.next( pnl );
    34    }
    35  };
    36
    37  /** shows the card with the id requested in the actioncommand */
    38  public Action showAction = new AbstractAction() {
    39    public void actionPerformed( ActionEvent e ) {
    40      //System.err.println( "ActionCommand=" + e.getActionCommand() );
    41      CardLayout cl = (CardLayout) ( pnl.getLayout() );
    42      if (e!=null) {
    43        cl.show( pnl, e.getActionCommand() );
    44      }
    45    }
    46  };
    47
    48  public static void main( String[] args ) {
    49    try {
    50      new Cards();
    51    } catch (Exception e) {
    52      System.err.println( e.getMessage() );
    53    }
    54  }
    55
    56}
    57

| Cards.java |