• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I make a different class for each JPanel  RSS feed

 
Aggelos wat
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
 
Joel Christophel
Ranch Hand
Posts: 250
1
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • 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:

 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!