File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Making two classes work together (newbeginner)" Watch "Making two classes work together (newbeginner)" New topic

Making two classes work together (newbeginner)

Ilo Nato

Joined: Oct 16, 2009
Posts: 6

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,
Ilo Nato

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

You are the man.

I agree. Here's the link:
subject: Making two classes work together (newbeginner)
It's not a secret anymore!