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

Making two classes work together (newbeginner)

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

You are the man.

Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic