• Post Reply Bookmark Topic Watch Topic
  • New Topic

Placing a JPanel From A Nother Class In To The Frame Of A Nother Class  RSS feed

 
Christian Cuevas
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there you can probably tell from the subject that I can't figure out how to place a JPanel from a class(Game) in to a another class(Core). I have bean stuck on this for about three days now I bean doing my research but no luck so now I think I should ask directly so here I am. Now to state clearly I am trying to place a JPanel named Game_Screen witch is in another class named Game into a JFrame named frame witch is in a another class named Core.Now booth of this classes are with in the same package and my IDE Is Eclipse.The JPanel Game_Screen has other swing pieces attached to it that should also be added with the panel on to the frame.But the change is screen should only happen when I click the buttons New Legend(N),Load Legend(L),Help(H) what already happens is that when you click any of this buttons menu.setVisible(false); is activated making everything on screen at the time disappear from the screen but the panel does not a pear.Help?

Here's my code:





Any help?
 
Campbell Ritchie
Marshal
Posts: 56587
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I have added code tags to your code. Always use them: doesn't it look better I also removed some of the ************ which simply make the lines too long and some unnecessary blank lines.

you should not create a panel as a local variable in a method and use it elsewhere. It ceases to exist (goes out of scope) when you go outside the method. Nor should you want to use such a variable. You should have a class which assembles all your GUI components in its constructor. Put them all together in the constructor (or a setUpGUI method). Call setVisible(true) last, after everything has been added.

Don't use null layouts and setBounds.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!