It's not a secret anymore!*
The moose likes Swing / AWT / SWT and the fly likes Making two classes work together (newbeginner) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Making two classes work together (newbeginner)" Watch "Making two classes work together (newbeginner)" New topic
Author

Making two classes work together (newbeginner)

Ilo Nato
Greenhorn

Joined: Oct 16, 2009
Posts: 6
Hi,

I trying to use jmenuitem to call other class.
When you click the jmenuitem you get the other class gui.

But mine actionlistener part working. It removes all but doesnt fill/get the from other class.
Here is the codes.

First one is the main:


The second one is the other class. i want to use.;


I can make them work with only 1 class. when there are 2 class i get problem.
I am doing it to learn more aboout Java.
I appreciate if anyone could help.
Janus Engstrøm
Ranch Hand

Joined: Nov 01, 2006
Posts: 44
Hi Ilo,

First of all:
You don't need line 27, as pane already is your contentPane and app is added to that in line 21. Since pane is your contentPane you don't need to change that as you do in line 52.

Try to see here:


As you can see, I remove app from the contentPane, add et.getGui() to it and force a repaint of the contentPane.

Now to your problem:
The size of the panel taken from Anotherclass hasn't been set. True, you just add the app to the conentPane of the JFrame and app is shown in the correct size, but that is because of line 60. Your app is Anotherclass hasn't been shown so it doesn't have an adjusted size, it is 0 by 0 pixels. In the example above I also call pane.toLayout() to force a re-layout of the components added to the pane, in this case the et.getGui()-panel. This results in the et.getGui()-panel being resized according to it's parent container's size.


Hope this clarifies a little.

Kind regards,
Janus
Ilo Nato
Greenhorn

Joined: Oct 16, 2009
Posts: 6
Damm... it worked

You are the man.

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Making two classes work together (newbeginner)