See MVC design Patterns through Java Swing

Source: Internet
Author: User

A good user interface (GUI) design can often find a corresponding performance in the real world. For example, if you have a simple button in front of your computer that resembles a keyboard key, however, it is such a simple button that we can see a GUI design rule, which consists of two main parts, part of which makes it have the action characteristics that the button should have, for example, it can be pressed. The other part is responsible for its performance, such as whether the button represents a or B.

Look at these two points and you find a powerful design approach that encourages reusing reuse rather than redesigning redesign. You find that the buttons have the same mechanism, you can create "different" buttons by spraying different letters on top of the button instead of redesigning a drawing for each button. This greatly reduces the time and difficulty of design work.

If you apply the above design ideas to the software development field, it is not surprising to achieve similar results. A very wide range of technical Model/view/controller (MVC) applied in the field of software development is an implementation of this idea.

That's great, of course, but maybe you're starting to wonder what this has to do with the user interface design (Swing) in Java base class JFC (Java Foundation Class)? OK, I'll tell you.

Although the MVC design pattern is often used to design the entire user interface (GUI), JFC designers have used this design pattern in an ingenious way to design a single component (Component) in swing, such as table jtable, tree JTree, Combine Drop-down list boxes JComboBox and so on. These components have a model, a view, a controller, and these model,view,controller can be changed independently, even when the component is being used. This feature makes it very flexible to develop the GUI interface's toolkit.

Well, come on, let me tell you how it works.

MVC design Pattern

As I have just pointed out, the MVC design pattern divides a software component area into three different parts, Model,view,controller.

Model is the component state and low-level behavior of the part, it manages its own state and handle all the state of operation, model itself does not know how to use their own view and controller, the system maintains its relationship with the view, When model has changed the system is also responsible for notifying the corresponding view.

View represents a visual presentation of the data contained in the management model. A model can have more than one view, but it is rarely the case in swing.

Controller manages the control of the interaction between model and user. It provides methods to handle situations where the state of the model changes.

Use the buttons on the keyboard example to illustrate: model is the whole mechanism of the button, View/controller is the surface part of the button.

The following figure explains how to divide a JFC developer's user interface into Model,view,controller, noting that View/controller is merged together, which is the common usage of the MVC design pattern, which provides the user interface (UI) of the component.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.