Through Java Swing to see the MVC design mode

xiaoxiao2021-03-06  68

Author: vipcowrie compilation

A good user interface (GUI) can usually find the corresponding performance in the real world. For example, if a simple button similar to the computer keyboard button is placed in front of your face, it is such a simple button, we can see the rules of a GUI design, which consists of two main parts. A portion allows it to have a button to have an action characteristic, for example, can be pressed. Another part is responsible for its performance, such as this button represents A or B. Seeing that these two points you discovered a very powerful design method, this method encouraged Reuse instead of redesigned Redesign. You find that the button has the same mechanism, you only need to create a "different" button on the top of the button, without re-designing a drawing for each button. This greatly reduces the time and difficulty of designing work. If you apply the above design ideas to the software development field, the achieved effect is not surprising. A very broad technology model in the software development area Model / View / Controller (MVC) is an implementation of this idea. This is of course very good, but maybe you start to doubt this and the user interface design section (SWING) in Java Foundation Class is related? Ok, let me tell you. Although the MVC design mode is usually used to design the entire user interface (GUI), JFC designers are originally used to design such design patterns to design a single component in Swing, such as form JTABLE, Tree JTree , Combined drop-down list box JCOMBOBOX, etc. These components have a Model, a view, a Controller, and these models, view, and controller can be changed independently, that is, when the components are being used. This feature enables the development of the toolbag for the GUI interface to be very flexible. Ok, come, let me tell you how it works. The MVC design mode is like I have just pointed out, MVC design mode divides a software component into three different parts, Model, View, Controller. Model is part of the component status and low-level behavior, which manages its own state and handles all the status of the status. Model does not know who uses your own view and controller, the system maintains the relationship between it and the relationship When MODEL has changed the system, it is also responsible for notifying the corresponding view. View represents a visual presentation of the data contained in Model. A Model can have more than one view, but there is little situation in swing. Controller manages the interaction between Model and users. It provides some way to process the situation when the Model changes. Use the example of the button on the keyboard to explain: Model is the entire mechanical device of the button, and View / Controller is the surface portion of the button. The following diagram explains how to divide a JFC development user interface into model, view, controller, note that View / Controller is incorporated together, this is the usual usage of MVC design mode, which provides components for user interface (UI) .