Forums Register Login

Making two classes work together (newbeginner)

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Damm... it worked

You are the man.

Thanks.
Right! We're on it! Let's get to work tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1774 times.
Similar Threads
OO Question
Adding background image to JDesktopPane?
Adding background image to JDesktopPane
JFrame.getContentPane(Jpanel) null pointer exception
Invisible Jpanels with jmenu
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 02:58:33.