• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
John Quach
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • 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!
 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!