Java and Model View Control MVC - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Java and Model View Control MVC

Description:

The model piece is responsible for the state and the behaviour of the module. ... that allows for changes occurring at run-time rather than during compilation. ... – PowerPoint PPT presentation

Number of Views:1917
Avg rating:3.0/5.0
Slides: 13
Provided by: dallass
Category:

less

Transcript and Presenter's Notes

Title: Java and Model View Control MVC


1
Java and Model View Control -MVC-
  • Vangelis Mavridis
  • COMM3C Java Network Programming
  • 11 June 2003

2
Introduction to the MVC
  • Model/View/Controller is a general pattern that
    is being used for designing user interfaces.
  • MVC was first introduced as part of the Smalltalk
    programming language.
  • Its implementation in Java can be found in the
    Swing user interface components that are included
    in the Java Foundation Classes (JFC).

3
Introduction to the MVC 2
  • Other implementations of MVC can be found in
  • CAD systems, where design can be viewed from
    different perspectives.
  • Charts such as pie-charts, bar-charts or line
    charts that share common data.

4
MVC architecture
  • According to the MVC architecture, all software
    modules are separated into three distinct pieces
    a model, a view, and a controller.

Model
View
Controller
5
MVC architecture 2
  • The model piece is responsible for the state and
    the behaviour of the module. Here, all changes on
    the state are monitored and executed.
  • The view piece is responsible for the
    visualisation of the state from the model.
    Multiple views can be applied to a model.
  • The controller piece manages the interaction from
    the user with the model. Through the controller,
    changes can be made to the state of the model.

6
Benefits of MVC
  • Flexibility and reuseability.
  • The dynamic relationship between the model and
    view pieces that allows for changes occurring at
    run-time rather than during compilation.
  • The separation of a program into modules allows
    for problems to be faced easier.

7
Benefits of MVC 2
  • Designing parts of the program separately at
    run-time can help manageability and future
    modifications.
  • Future modifications can be made easier by
    changing only segments of the program.

8
MVC and Java Swing
  • MVC is implemented in Java in the Swing UI
    components of the JFC classes.

Model
View
Controller
9
MVC and Java Swing 2
  • Java swing uses a different view of the MVC
    pattern. Here, the model piece remains individual
    while the view and controller pieces are combined
    into one component.
  • All the components in Java Swing have already
    defined data models. These can be either built-in
    classes or user defined classes.

10
The benefits of MVC in Java
  • Implementing the MVC pattern in Java results to
    the creation of a higly flexible user interface
    toolkit.
  • Therefore, Swings components such as buttons,
    tables or scrollbars can be modified
    simultaneously while they are being used.

11
An example of use
  • How MVC is applied in the Java Swing set can be
    shown by examining the button component.
  • The ButtonModel interface shows the behaviour of
    the model in the button component. Here the
    instance of the button is created by the model.
    Also, through the model the button behaviour is
    defined.
  • The same interface also uses methods aimed at
    questioning or altering the internal state of the
    button, adding and removing event listeners or
    initiating events.

12
An example of use 2
  • The ButtonUI interface shows how the view and
    controller act in the button component. When this
    interface is used by classes, code can be written
    for creating the visual appearance of a button as
    well as handling input coming from the keyboard
    or the mouse.
  • Some of the methods used by the interface are
    the Paint method, the handling of AWT events or
    the handling of geometric information.
Write a Comment
User Comments (0)
About PowerShow.com