(c) University of Washington08-1 CSC 143 Models and Views Reading: Ch. 18.

Slides:



Advertisements
Similar presentations
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Advertisements

1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Object Oriented Programming with Java (150704).   Applet  AWT (Abstract Window Toolkit)  Japplet  Swing Types of Applet.
OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
1 Model View Controller. 2 Outline Review Definitions of MVC Why do we need it? Administiriva Changing the display Event flow Dragging at interactive.
Graphics Programming. In this class, we will cover: The difference between AWT and Swing Creating a frame Frame positioning Displaying information in.
Graphical User Interface (GUI) Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
System Architecture Lecture 3 CSE 111 Spring /22/20151Copyright William E. Howden.
James Tam Introduction To Design Patterns You will learn about design techniques that have been successfully applied to different scenarios.
Graphical User Interface (GUI) Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Object-Oriented Analysis and Design
Design patterns Observer,Strategi, Composite,Template (Chap 5, 6)
1 Object Oriented Design & Patterns Part 1. 2 Design Patterns Derived from architectural patterns: –rules for design of buildings –describe common problems,
Model View Controller (MVC) Architecture. Terminology and History MVC evolved from Smalltalk-80 Has become a key pattern in web based applications – If.
Stanford hci group / cs376 research topics in human-computer interaction UI Software Tools Scott Klemmer 27 October 2005.
March R McFadyen1 Figure 30.2 Layers in NextGen They only have three layers in this architecture Each layer is shown as a UML Package No separate.
Part two. 3.2 operating system architecture  Software have two categories  Application software  System software  Application software: consists of.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
CSE 331 Software Design & Implementation Dan Grossman Spring 2015 GUI Event-Driven Programming (Based on slides by Mike Ernst, Dan Grossman, David Notkin,
MVC pattern and implementation in java
Design Patterns and Graphical User Interfaces Horstmann ,
MVC and MVP. References enter.html enter.html
Model View Controller (MVC) Rick Mercer with a wide variety of others 1.
Java Swing, Events and MVC Optional Readings: Eckel’s Thinking in Java: Chap 14 (
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
CS 3131 Introduction to Programming in Java Rich Maclin Computer Science Department.
Swing and MVCS CompSci 230 Software Construction.
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
(c) University of Washington07b-1 CSC 143 Java Events, Event Handlers, and Threads Reading: Ch. 17.
School of Computer Science & Information Technology G6DICP - Lecture 17 GUI (Graphical User Interface) Programming.
Java Graphics. Review 3 kinds of elements in components API? Layout managers Events Extend vs. Implement.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
3461 Model-View Controller Advanced GUI concepts.
CSCE 121: Introduction to Program Design and Concepts, Honors Dr. J. Michael Moore Spring 2015 Set 15: GUIs 1.
Model View Controller (MVC) Bigger than a Pattern: It’s an Architecture Rick Mercer with help from many others 1.
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
SWING 101. IF YOU GET LOST - IMPORTANT LINKS  Swing articles:
Model View Controller A Pattern that Many People Think They Understand, But Has A Couple Meanings.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
1 Java Model-View-Controller - see programming.html#concepts.
Lec.10 (Chapter 8 & 9) GUI Jiang (Jen) ZHENG June 27 th, 2005.
Model View Controller MVC Web Software Architecture.
Java Direct Manipulation Chris North cs3724: HCI.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Event-Driven Programming 1.
Model View Controller (MVC) Bigger than a Pattern: It’s an Architecture Rick Mercer with help from many of others 1.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Java Dynamic Graphics.
ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMMING PRACTICES Model View.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
1 CSE 331 Model/View Separation and Observer Pattern slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia.
Model View Controller (MVC) an architecture Rick Mercer with help from many of others 1.
L10: Model-View-Controller General application structure. User Interface: Role, Requirements, Problems Design patterns: Model – View – Controller, Observer/Observable.
MiniDraw Introducing a Framework... and a few patterns.
21-Jun-16 Swing Basics and Model-View- Controller.
Programming Paradigms, Software Architectural Patterns, and MVC CS 378 – Mobile Computing for iOS Dr. William C. Bulko.
Introducing a Framework ... and a few patterns
Observer Design Pattern
Understand Windows Forms Applications and Console-based Applications
CSE 331 Software Design and Implementation
CS102 – Bilkent University
CSE 331 Software Design and Implementation
Model-View-Controller Patterns and Frameworks
Model, View, Controller design pattern
Presentation transcript:

(c) University of Washington08-1 CSC 143 Models and Views Reading: Ch. 18

(c) University of Washington08-2 Overview Topics Displaying dynamic data Model-View Model-View-Controller (MVC) Reading: Textbook: Ch. 20

(c) University of Washington08-3 Review: Repainting the Screen GUI components such as JPanels can draw on themselves using a Graphics context Problem: Drawings aren’t permanent – need to be refreshed Window may get hidden, moved, minimized, etc. Even components like buttons, listboxes, file choosers etc. also must render themselves. Seldom a reason to override paint for such components. There are indirect but more convenient ways to change the rendering. Solution: A "callback" method called paintComponent

(c) University of Washington08-4 Review: Using paintComponent Or just plain paint for older AWT components. Every Component subclass has a paint ( paintComponent ) method Called automatically by the system when component needs redrawing Program can override paintComponent to get the Graphics and draw what is desired To request the image be updated, send it a "repaint" message paintComponent( ) is eventually called Footnote: "Render" is the word for producing the actual visual image Rendering may take place at multiple levels Ultimate rendering is done by low-level software and/or hardware

(c) University of Washington08-5 Drawing Based on Stored Data Problem: how does paintComponent( ) know what to paint? The picture might need to change over time, too. Answer: we need to store the information somewhere Where? Some possibilities Store detailed graphical information in the component Lines, shapes, colors, positions, etc. Probably in an instance variable, accessible to paintComponent Store underlying information in the component Store objects that know how to paint themselves Store references to the underlying data and query it as needed data object returns information in a form that might differ from the underlying data paintComponent translates the data into graphics All of these approaches can be made to work. What is best?

(c) University of Washington08-6 Model-View-Controller Pattern Idea: want to separate the underlying data from the code that renders it Good design because it separates issues Consistent with object-oriented principles Allows multiple views of the same data Model-View-Controller pattern Originated in the Smalltalk community in 1970’s Used throughout Swing Although not always obvious on the surface Widely used in commercial programming Recommended practice for graphical applications

(c) University of Washington08-7 MVC Overview M odel Contains the “truth” – data or state of the system "Model" is a poor word. "Content" or "underlying data" would be better. V iew Renders the information in the model to make it visible to users in desired formats Graphical display, dancing bar graphs, printed output, network stream…. C ontroller Reacts to user input (mouse, keyboard) and other events Coordinates the models and views Might create the model or view Might pass a model reference to a view or vice versa

(c) University of Washington08-8 MVC Interactions and Roles Model Maintains the data in some internal representation Supplies data to view when requested Possibly in a different representation Advanced: Notifies viewers when model has changed and view update might be needed Generally unaware of the display details View Maintains details about the display environment Gets data from the model when it needs to Renders data when requested (by the system or the controller, etc.) Advanced: Catches user interface events and notifies controller Controller Intercepts and interprets user interface events routes information to models and views

(c) University of Washington08-9 MVC vs MV Separating Model from View......is just good, basic object-oriented design usually not hard to achieve, with forethought Separating the Controller is a bit less clear-cut May be overkill in a small system. Often the Controller and the View are naturally closely related Both frequently use GUI Components, which the Model is unlikely to do. Model-View Pattern: MV Folds the Controller and the View together.

(c) University of Washington08-10 Implementation Note Model, View, and Controller are design concepts, not class names Might be more than one class involved in each. The View might involve a number of different GUI components Example: JFileChooser MVC might apply at multiple levels in a system A Controller might use a listbox to interact with a user. That listbox is part of the Controller However, the listbox itself has a Model and a View, and possibly a Controller.

(c) University of Washington08-11 Example: Simple Simulator Framework Class SimModel – model for a particle simulation (Same basic idea as uwcse.sim, but simpler) SimModel maintains the state of the simulation – keeps track of the objects that have been added to the world Interface SimThing – anything that implements this can be added to the simulation Interface SimView – anything that implements this can be a viewer of the model (No controller for this example)

(c) University of Washington08-12 Model-View Interaction It's possible to have more than one viewer A viewer tells the model that it wants to be notified when something interesting happens The model contains a list of all interested viewers When something happens (a cycle in the simulation has occurred, for example), the model calls the notify( ) method of each viewer Viewers can react however they like This illustrates the "observer pattern" used heavily in the Java user interface libraries, among other places

(c) University of Washington08-13 An Example Simulation Class Ball implements SimThing A bouncing ball that updates its position on each action( ) and reverses direction if it hits the edge Implements paintComponent(Graphics g) to draw itself when asked Class BallGraphicsView implements SimView A JPanel that is notified after each cycle of the simulation just requests repaint( ) Method paintComponent gets the list of all Ball objects from the model and asks each one to paint itself using the supplied Graphics object