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 s开发者_C百科ingle 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?
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.
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.
精彩评论