• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JDesktopPane creates inner frame menuItem actionPerformed does not.

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.




 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your example is almost "the same" as the one from Sun's for internal frames:
- InternalFrameDemo.java
- MyInternalFrame.java
 
James Howerton
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it is. But I can't get it to load more than one internal frame
thanks
 
James Howerton
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only differences are that I have a class tho add to the frame.add() and the JMenu is created in the Menu.java.

I have to do something to the action performed or something because it calls createFrame.
Something is wrong with my menuItem.

It can create how ever many frames I want if I call createFrame over and over in the class
'
I tried the .addActionListener

I tried the



no new frames
thanks








E
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what do you think this line does? (in mousePressed)

dp=new DesktopPane();
 
James Howerton
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the desktop runs from main creating

the first internal frame perfect

it says it created more (too many

infact)

but nothing gets painted to JDesktopPane

is there a way to get the Jmenu to

create one more internalframe?



Desktop class



Jmenu actionEvent




output


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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

JMenu item



the new CreateNewGuide.class


the error



output
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

curious line this
public void CreateNewGuide() throws FileNotFoundException, IOException, PropertyVetoException {

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
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My getter method had code to Jdp=null I removed that but same error
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My original mission was to make more packages and classes to make more generic classes.

That is why I couldn't call my JDesktopPane from my JMenuBar

I had to move it to my JDesktopPane and it makes sense now.
The menu is for a the window

here is the code it works good. On to the next problem. One problem solved 12 more created.

Thanks again for your help.

 
If tomatoes are a fruit, then ketchup must be a jam. Taste this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic