• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
Bartenders:
  • Himai Minh
  • Carey Brown
  • Frits Walraven

CardLayout

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to the Swing / AWT / SWT / JFace forum...
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Why is the word "abbreviation" so long? And this ad is so short?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic