GeeCON Prague 2014*
The moose likes Applets and the fly likes Swapping Panels in an Applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Applets
Bookmark "Swapping Panels in an Applet" Watch "Swapping Panels in an Applet" New topic
Author

Swapping Panels in an Applet

Larry Homes
Greenhorn

Joined: Jan 18, 2009
Posts: 25
Hello

I am moderately experienced in Java, but inexperienced in making GUI's and even less experienced in applets. So, I have an applet that has a panel. I want to be able to have an actionListener in this panel swap panels in the applet. Here is some example code to illustrate what I need:



My solution after much thinking was to pass around an instance of the applet to all the panels, but I have no idea if this is good form or a terrible idea. So something like:



Is this good form or is there a better, more standard way of doing this. I've looked around, but almost all the examples I found were too simple.


Thanks
Rok Štelcer
Ranch Hand

Joined: Nov 03, 2009
Posts: 101
Hi,

This has nothing to do with Applets per se ... all you need is a CardLayout.


Regards,
Rok


SCJP, SCWCD
Larry Homes
Greenhorn

Joined: Jan 18, 2009
Posts: 25
Hello,

Yes I didn't know whether to post this in the swing forum or here.

So using cardlayout, something like this?



Is there a more elegant way of finding the panel with the CardLayout than a chain of getParent()?


Thanks for the help
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

I wouldn't say "more elegant", I would say "more usual"; just pass around references to anybody who needs them:
 
GeeCON Prague 2014
 
subject: Swapping Panels in an Applet