Hi,
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.
showCard1()
{
((CardLayout)cards.getLayout()).show(cards, anigif);//anigif is a String
}
etc...
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.setLayout(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,
Rob
12-03-2000, 12:42 AM
Robert
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
me.
thanks,
Robert