DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Robert Guest

    cardLayout question

    How do I change a card panel in various places in my code.
    The places I would like to add this action are in the following blocks of
    code : a WindowEvent(windowClosing) , a method that is called when a button
    is clicked, and an instanceof MenuItem.

    After much stuggle with the CardLayout using AWT I have managed to add several
    images to theCardLayout and can be display them with:
    ((CardLayout)cards.getLayout()).show(cards, anigif);
    or ((CardLayout)cards.getLayout()).show(cards, guitargif);
    The gui is a Frame to which images(to the default panel I guess) are painted
    (to the default panel I guess), and a panel added (East) nesting 2 panels
    using GridLayout. One of these nested panels is the card panel in question
    (cards). A class displaying animated gifs used to display the gifs in their
    respective panels :the first card is guitargif, the second is anigif.

    My question is this, how do I adapt the code so that various
    actions perform this ? It only seems to work with the constructor.
    My code is probably 1.1 (?) and I am testing it using java 1.3.

    I am have tried adding ((CardLayout)cards.getLayout()).show(cards, anigif);
    to various places in the rest of the code, and though it compiles I get
    a java.lang.NullPointerException upon execution. I have also tried it with
    methods ie.
    ((CardLayout)cards.getLayout()).show(cards, anigif);//anigif is a String

    The full code for the main class is at www.pathcom.com/~robertle/CardQuestion.html
    with relevent code in bold.

    Here is a fragment:
    final static String anigif = "gif display";
    final static String guitargif = "guitar pic display";
    Panel pan;
    Panel cards;
    final static CardLayout cardLayout = new CardLayout();
    cards.add(anigif, imcan);
    guitar guitarPic = new guitar();//gif display class
    cards.add(guitargif, guitarPic);//gif display class
    ((CardLayout)cards.getLayout()).show(cards, anigif);
    pan.add("East", cards);

    ((CardLayout)cards.getLayout()).show(cards, anigif)
    Many thanks,

  2. #2
    Robert Guest

    Re: cardLayout question

    note: I have moved servers and the pathcom web and email address is no longer
    valid. If you would like to help and need to see more code please email

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.