• Post Reply Bookmark Topic Watch Topic
  • New Topic

JDesktopPane spawning Internal Frames  RSS feed

 
Christopher Brooks
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having trouble deciding how to go about controlling the objects in my application. I want to have a JDesktopPane which when selecting menu options will spawn internal frames. The internal frames should themselves be able to spawn other internal frames.
My question is how is this normally done. Should I create a singleton JDesktopPane with methods in it to spawn every type of internal frame possible, that way it would be easy to get the frames to appear by calling the JDesktopPane instance from anywhere in the application, even from the other internal frames. In other words have the JDesktopPane create all the objects.
Or, should I allow the Internal frames to create the other Internal Frame objects in their methods?
In fact should I be creating the objects in the methods at all or should I be doing that in the constructor, I am getting very confused!?
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a bean that handles that. I hook the menu items / buttons up so that the bean gets called when the menu item is selected. The bean is configurable to indicate the class name of the desired Internal Frame, and it uses Reflection to load the frame.
Normally, the class is not actually an Internal Frame but rather a JPanel, which the bean then constructs an Internal frame around. This way, the bean can be used to load internal frames / top level frames / Dialogs / etc, and builds the appropriate wrapper around the panel to do that.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm moving this to the Swing / JFC / AWT forum...
(Just to warn ya, this might get bounced again to the OO forum.)
 
Christopher Brooks
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joel, is that a particular design pattern that you are talking about in your bean example? Is there one that I might think about using for this scenario? Do you see anything wrong with the JDesktopPane being a singleton idea?
 
Christopher Brooks
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Christopher Brooks
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any ideas?
 
Christopher Brooks
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i was thinking in my GUI_DesktopPane class, to have menu items and then also the methods:

I then have various classes like GUI_MemberStatus that extends JInternalFrame and implements ActionListener. Now what should I do about those "special" internal frames that need to spawn internal frames in the JDesktopPane as well?
Should I:
a) Make the creatFrame method static
b) Create the new internal frame within the "special" internal frame. Pass a reference of GUI_DesktopPane into the "special" internal frames, then call its createFrame method and pass it the new internal frame.
c) Make the GUI_DesktopPane a singleton. Call getinstance().creatFrame from wherever i want.
d) Stop posting stupid questions on the forum, open up a plumbing business and make more money than any programmer would dream of.

NEP - edited post to format code so it wasn't extra wide...
[ October 30, 2003: Message edited by: Nathan Pruett ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!