• 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
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can I make a different class for each JPanel

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi to all,
as I have said many times,I am a begginer in Java. I have made four apps and I want to put each of them in one project to make a big app.So,I have made a JFrame which has a lot of Jpanels inside.My question is how I can write different class for every Jpanel because I try to put all of them in one class,and it was not a good idea. Also, I do not want to open an other window when I choose an app. I want to have a Jpanel for every app.I use Cardlayout,I have read the tutorials but I can not understand.Also,I thought to make a different JFrame but I know it is not a good idea,and I do not want to open a different window when I open a different app.
Thank you
 
Ranch Hand
Posts: 250
1
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could use a JTabbedPane, and have a separate project under each tab.

As for making JPanel classes, you start out with:

 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have 4 separate apps that you want to combine into one application and each application currently has it's own gui then it should be fairly simple to do but it all depends on how you have written the existing code. If the top level gui classes for those apps extends JFrame rather than JPanel then you will have to change your code so that they extend JPanel. If you still want the apps to be able to run standalone then in their main methods add code to create a JFrame, add the instance of the class to it and then display it.

In simple terms you create a new class for your combined application which creates the JFrame, CardLayout panel etc and also the instances of each of the other 4 apps. Then you add each instances' top level GUI (which is a sub class of JPanel) to the panel containing the CardLayout manager.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic