JDesktopPane creates inner frame menuItem actionPerformed does not.
James Howerton
Ranch Hand
Joined: Mar 14, 2009
Posts: 82
posted
0
Hello could someone help me figure out how to make my menu item work? It calls createFrame() to add an additional inner frame. It runs but nothing is added to the JDesktopPane.
back in the create Frame() number of frames= 0
internal frame openFrameCount= 1
start obj() type= guide
createGuideInternalFrame
back in the create Frame() number of frames= 1
internal frame openFrameCount= 2
start obj() type= guide
back in the create Frame() number of frames= 2
internal frame openFrameCount= 3
start obj() type= guide
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
read your code
DesktopPane frame = new DesktopPane();
JDesktopPane jdp;
setContentPane(jdp);
...and in createFrame();
InternalFrame frame=new InternalFrame();
jdp.add(frame);
and in your actionListener
DesktopPane dp = new DesktopPane();
dp.createFrame();
how many DesktopPane()'s are shown?
hint: 'new' means another one
James Howerton
Ranch Hand
Joined: Mar 14, 2009
Posts: 82
posted
0
It looks like in my actionListener I am making a new JDesktopPane which calls createFrame();
I guess I am not sure how to have the actionListener call the createFrame(); without the importing the DeskTopPane class a dp so it knows what the createFrame() is "dp.createFrame();"
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
> It looks like in my actionListener I am making a new JDesktopPane which calls createFrame();
actually, you are creating another instance of 'DesktopPane' (a JFrame),
which calls createFrame()
>I guess I am not sure how to have the actionListener call the createFrame();
> without the importing the DeskTopPane class a dp so it knows what the createFrame() is "dp.createFrame();"
usual way is:
DesktopPane.this.createFrame();
James Howerton
Ranch Hand
Joined: Mar 14, 2009
Posts: 82
posted
0
The only thing I could think of:
My JDesktop.class makes the JDesktop pane
a new internal frame class is called that creates and returned to it and adds it fine.
I used a setter to set the JDesktopPane into This new class
my actionPerformed calls the void method that of this new class and it tries the same thin only it tries to have the JDesktopPane that is now in the class
add the InternalFRame.
just looking at the code, you would need to call this
public void setJdp(JDesktopPane jdp) {
before calling this
CreateNewGuide() ---> jdp.add(frame);
otherwise jdp will be null
why have the method name the same as the class name - most will think it should be a constructor, with errant 'void'm included
why all the unrelated throws exceptions
James Howerton
Ranch Hand
Joined: Mar 14, 2009
Posts: 82
posted
0
I changed the order of jdp creation
it still runs good from main but the
It does not want to deal with jdp.add(frame) in the createNewFrame()
JMenu item
the new CreateNewGuide.class
the error
Thanks for your time.
James Howerton
Ranch Hand
Joined: Mar 14, 2009
Posts: 82
posted
0
My getter method had code to Jdp=null I removed that but same error
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
you still haven't addressed the problem mentioned in my earlier post
in CreateNewGuide() you have this
public JDesktopPane jdp;
then, when you call cnf.CreateNewGuide(); (assuming [CreateNewFrame] cnf=new CreateNewGuide() is a typo)
includes
jdp.add(frame);
so, jdp has to be null
you can either use a constructor to pass a reference of the desktoppane to jdp, or
CreateNewFrame cnf=new CreateNewGuide();
cnf.setJdp(ref to desktoppane);//<----------------add this line
cnf.CreateNewGuide();
James Howerton
Ranch Hand
Joined: Mar 14, 2009
Posts: 82
posted
0
since it did not like setting the frame from the InternalFrame class
I tried to set the frame created in the jdp class.
and told the setter to add the frame to jdp.
but there needs to be something in the JDesktopPane class to be waiting for the new frame.
should I be trying a Runnable class?
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
> should I be trying a Runnable class?
I can't see how a runnable class would help, you need to pass a reference of the
visible JFrame's desktoppane all the way down the line to where it is used in CreateNewGuide()
It might be worth you starting another project, just to simplify everything
only include the desktoppane and internal frame stuff, along with a single menuitem with actionListener.
if you still can't get it working, you'll have something small and complete to post here.
your code posted so far is very difficult to follow, things like
public class CreateNewGuide extends JInternalFrame
why would it extend JIternalFrame, when it uses an inner class that also extends JInternalFrame
James Howerton
Ranch Hand
Joined: Mar 14, 2009
Posts: 82
posted
0
My original mission was to make more packages and classes to make more generic classes.