Sie sind auf Seite 1von 3

Model View Controller Introduction:

Model - View - Controller (MVC) is an architectural pattern used in software engineering. The MVC pattern is most commonly used to create interfaces for software applications, and, as the name implies, consists of three elements: Model: contains the application data and logic to manage the state of the application. View: present the user interface. Controller: Handles user inputs to change the state on the application.

MVC
Mod e l

Vie w

Con trolle r

Viewtellsto controller handle user inputs Controller changes model state Model tellsview to updateitself View reads state information from model updatesitself.

and

View tells to controller handle user inputs Controller changes the model state Model tells view to update itself View reads state information from model and updates itself. Though MVC comes in different flavors, control flow is generally as follows: The user interacts with the user interface in some way (for example, by pressing a mouse button). The controller handles the input event from the user interface, often via a registered handler or callback, and converts the event into an appropriate user action, understandable for the model. The controller notifies the model of the user action, possibly resulting in a change in the model's state. (For example, the controller updates the user's shopping cart).[5] A view queries the model in order to generate an appropriate user interface (for example the view lists the shopping cart's contents). The view gets its own data from the model. In some implementations, the controller may issue a general

instruction to the view to render itself. In others, the view is automatically notified by the model of changes in state (Observer) that require a screen update. The user interface waits for further user interactions, which restarts the control flow cycle. The separation of responsibilities among the model, view and controller elements allows easy substitution of elements without disruptions to the overall application. This lets us easily expand applications based on the MVC pattern to meet changing requirements. Business applications consist of user interface (UI), business logic, and data models. When UI, business logic and data are collapsed into one object in rich users interface, it can lead to some of the following problems: Difficult to use the data outside that object Hard to change the UI, when UI and data are locked in the same object. Hard to use multiple views of the same data

Difficult to synchronize multiple view of the same data.

SWING Swing is the primary Java GUI widget toolkit. It is part of Oracle's Java Foundation Classes (JFC) an API for providing a graphical user interface (GUI) for Java programs. Swing is a platform-independent, Model-View-Controller GUI framework for Java. It follows a single-threaded programming model. Swing is a Graphical User Interface (GUI) API, offering a set of components that can be used to build rich desktop interfaces. This includes basic elements such as windows, buttons, scrollbars, etc., as well as more complex compound objects such as file choosers, color choosers and combo boxes. Architecture:Swing components are Java Beans, and are built around the Model-View-Controller (MVC) programming paradigm. This paradigm separates an application's business logic from its user interface so that they can be evolved independently. JComponent is the core Controller class which coordinates Models and Views to display a final user component. All Swing components are inherited from JComponent. Note that components can have different views represented by different UIs. The javax.swing.plaf package contains ComponentUI, which is the core class for the View and is a template for other components that inherit from it. ComponentUI is responsible for the ultimate painting of pixels on the screen. A Model controls the data in components, from simple things such as the state of a check box, to the more complex rows and columns data structures used for a table. ComboBoxModel and TableModel are example model classes.

Das könnte Ihnen auch gefallen