Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swapping Panels in an Applet

 
Larry Homes
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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


Regards,
Rok
 
Larry Homes
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't say "more elegant", I would say "more usual"; just pass around references to anybody who needs them:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic