File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CardLayout

 
Matthew Fyffe
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing / AWT / SWT / JFace forum...
 
Petr Blahos
Ranch Hand
Posts: 131
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic