tags:

views:

139

answers:

2

I am currently trying to program in Scala but I guess this can generally applies to other programming as well?

In Swing, we generally organize our code and logic in a single class (perhaps our Frame or Panel). What I have learnt in the pass has always been dealing with a class as well. I am wondering if there is any medium size (not too large and complicated) project to view on?

How do we actually organize our code such as from login to view tables, update tables, so other tasks? Do we normally create a lot of frame, which seem to be what I learnt from Visual Basic? Or just a lot of panels, and have a frame to hold these frame? If it is second case, how would I actually pass down information from one panel to another as they are not actually directly related except through the frame.

Any guide on this organization?

+2  A: 

Investigate using Model View Controller (MVC) architecture. This way you have a model that stores your current state, a view that shows what you want how you want, and a controller (the business logic) that communicates between the two. This allows you to modify your model or view and not have to make too many changes to other places in your code. It also means you can reuse your view (GUI) on another model.

Using the above, you can have a controller that can see several panels and update them, as well as handle the actions on those panels and reflect changes to the model.

jackta101
See also http://stackoverflow.com/questions/3072979
trashgod
@trashgod, in the link that you have given, it is like we need to create 3 additional class for Model, View and Controller. Sorry, but any more example? :)
JohanSJA
@JohanSJA: The link mentions a more complex example. Were you looking for something simpler?
trashgod
@trashgod, ya. Thank you.
JohanSJA
+1  A: 

If I understand correctly from your comments, you were you looking for a simple example. Starting from this outline, the edit history of this simple example game shows the evolution of using the Model–View–Controller pattern to develop a GUI program. Although it seems more complicated at first, the value of the pattern is in decoupling the model and view. This allows them to be modified more independently.

trashgod