• 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

Is it possible to instantiate three classes into objects nestled in their own panels in one GUI?

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In an attempt to organize my code, I tried separating them into three different classes. My plan is a basic GUI with a gridlayout of 3 rows and 1 column.

I'd hope to nest each class into a panel for each box in the gridlayout, but I can't get it to work.


Its late and I got work early tomorrow. I might post the code tomorrow night.

Thank you in advance!
 
Ranch Hand
Posts: 326
Android Mac OS X Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To answer your question: Yes it is.

What you normally do is that you have one class that extends some sort of Window-based container, such as JWindow or JFrame and that takes care of anything that has to do with the topmost graphical object.

You then create classes that extends a suitable component or container, i.e. a JPanel, and from your topmost object, you instantiate new objects of that type. This means that if you need to have say two different panels that shows the same thing, but for different models, you can create two instances of that panel and assign different models to it. An example is if you show stats for two different players. It should look the same, but have the data from the different Player objects.

The best way to learn this, from my experience, is to physically draw your gui on paper and have the different components on different papers and then just move them around. I often do a mock on paper and when I need a UI-component, I actually go to the photo copier and make a new one. Then I modify it or write data on it. I also use small post-its to mark what model instance is used where.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic