aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes CardLayout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "CardLayout" Watch "CardLayout" New topic
Author

CardLayout

Matthew Fyffe
Greenhorn

Joined: Jul 11, 2003
Posts: 16
After playing with CardLayout on several programs, I've become curious on how to PROPERLY use CardLayout . I understand the show commands and what not, but I'm not sure what I should do with the items I want to show. Let me explain with my example. I wrote a program that has an opening menu in which you pick what you would like to do. When you select what you would like to do, the menu is replaced with a new screen that pertains to your selection from the opening menu. While I understand that this is the typical situation to use CardLayout, I'm not sure if I'm doing it right. The problem is, I create a separate class for each of the different screens that the user would be sent to, causing my project to have an abundance of class files. Am I supposed to create a separate class that extends JPanel for all of the various screens or is there a better way to do this? Thanks a lot!
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Swing / AWT / SWT / JFace forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Petr Blahos
Ranch Hand

Joined: Apr 28, 2004
Posts: 131
Hi Matthew,

It pretty much depends of other circumstances, but in general
the idea of having a class per window or a class per screen
is correct. I guess that your screens might have some common
characteristics. Then you can derive them from a common base class.
Sometimes you might be able to use the same class with different
parameters for different screens, for example if your screens
contain just a button and a text, but different texts for
different screens, you better used the same class with different
parameters. Or if the screens are super-simple you can have
everything in one class, but even in that case I would
recommend having the screens in separate classes. Therefore
it will be much easier to add additional screens or change
current screens in future.

Best regards,
Petr


Get a better web browser:<br /><a href="http://www.mozilla.org/products/firefox/switch.html" target="_blank" rel="nofollow">http://www.mozilla.org/products/firefox/switch.html</a>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: CardLayout