File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Swapping Panels in an Applet

Larry Homes

Joined: Jan 18, 2009
Posts: 25

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.

Rok Štelcer
Ranch Hand

Joined: Nov 03, 2009
Posts: 101

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


Larry Homes

Joined: Jan 18, 2009
Posts: 25

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

Joined: Oct 14, 2005
Posts: 19973

I wouldn't say "more elegant", I would say "more usual"; just pass around references to anybody who needs them:
I agree. Here's the link:
subject: Swapping Panels in an Applet
It's not a secret anymore!