How to properly construct a java gui framework?

C

***C.Steamer***

Basically I need to know how to set up a basic gui framework. I have heard
of the MVC approach but either I don't fully understand it or it doesn't
work properly for my needs. I simpley want to know a common structure how
most Java Applications will be constructed. Mainly, Should I have Say a
JFrame class that calls a MainPanel which in turn sets up all the Panels for
the program, and then say a ControllerClass which sets up all the
components. What do I do with the data. Specifically I am currently making a
simpe java card game application and I do that. I have a buch of Panels that
represent say my hand, or the deck. Know say I want to remove a card from
the display (say someone selected it to play). Should my panel class handle
all this or should there be some other type of class to handle user inputs
like perhaps a controller class. Obviously there must be a somewhat simple
way to organize the gui with the controls of a program. Any help would be
appreciated. I used the game as an example but this should be common to any
application on how to set up a organized java app so it is somewhat
managable and upgradable.

Thanks
 
S

steve

Basically I need to know how to set up a basic gui framework. I have heard
of the MVC approach but either I don't fully understand it or it doesn't
work properly for my needs. I simpley want to know a common structure how
most Java Applications will be constructed. Mainly, Should I have Say a
JFrame class that calls a MainPanel which in turn sets up all the Panels for
the program, and then say a ControllerClass which sets up all the
components. What do I do with the data. Specifically I am currently making a
simpe java card game application and I do that. I have a buch of Panels that
represent say my hand, or the deck. Know say I want to remove a card from
the display (say someone selected it to play). Should my panel class handle
all this or should there be some other type of class to handle user inputs
like perhaps a controller class. Obviously there must be a somewhat simple
way to organize the gui with the controls of a program. Any help would be
appreciated. I used the game as an example but this should be common to any
application on how to set up a organized java app so it is somewhat
managable and upgradable.

Thanks

you need to subclass it.

inside your JPanel , have it call other classes, for the sake of your
example, in a class called , perhaps "hand"


hand.addcard()
hand.remove card()
hand.countcards()
hand.returncurrentcards()

etc

to remove a card , simply call hand.removecard(card)
subclass it down to it's most basic operation, do not just write an
extension to JPanel , and stick all the shit in it , or it will end up as a
very big JPanel class.


The advantage , with this , is that there maybe some operations that can be
run in parallel.
By subclassing it out , you can fire up multiple processing threads.

if you have a large Jpanel, You COULD put all your graphic elements into
it.
But if instead you subclass out each part of your larger Jpanel to other
Jpanels (for example 5 JPanels), then you could fire up 5 threads & process
all 5 areas at the same time, leading to a faster GI update.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top