1 Object Oriented Design & Patterns Part 1. 2 Design Patterns Derived from architectural patterns: –rules for design of buildings –describe common problems,

Slides:



Advertisements
Similar presentations
G5BUID - Java Swing Laying out components Manage realized components Determine size and position Each container has a layout manager (usually)
Advertisements

Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Graphical User Interfaces
Java Software Development Paradigm Lecture # 12. Basics of GUI.
CS18000: Problem Solving and Object-Oriented Programming.
Graphic User Interfaces Layout Managers Event Handling.
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Object-Oriented Design & Patterns 2 nd edition Cay S. Horstmann Chapter 5: Patterns and GUI Programming CPSC 2100 Software Design and Development 1.
OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
Java Swing Toolkit Graphics The key to effectively using graphics in Java is understanding: –the basic components of the graphics library –the patterns.
Swing CS-328 Dick Steflik John Margulies. Swing vs AWT AWT is Java’s original set of classes for building GUIs Uses peer components of the OS; heavyweight.
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
Chapter 5 (Horstmann’s Book) Patterns and GUI Programming Hwajung Lee.
Design patterns Observer,Strategi, Composite,Template (Chap 5, 6)
Scott Grissom, copyright 2006Ch 11: GUI Slide 1 Graphical User Interfaces (Ch 11) Careful design of a graphical user interface is key to a viable software.
ITEC324 Principle of CS III Chapter 5 (Horstmann’s Book) Patterns and GUI Programming Modified from slides by Dr. Hwajung Lee.
Java Programming Chapter 10 Graphical User Interfaces.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Design Patterns and Graphical User Interfaces Horstmann ,
Welcome to CIS 083 ! Events CIS 068.
MSc Workshop - © S. Kamin, U.Reddy Lect 5 – GUI Prog - 1 Lecture 5 – GUI Programming r Inner classes  this and super r Layout r Reading: m.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
(c) University of Washington08-1 CSC 143 Models and Views Reading: Ch. 18.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Session 11 Border Layout, using Panels, Introduction to PinBallGame.
Session 10 CannonGame and Event-driven Programming.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
CS 151: Object-Oriented Design October 24 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
1 Outline 1 Introduction 2 Overview of Swing Components 3 JLabel 4 Event Handling 5 TextFields 6 How Event Handling Works 7 JButton 8 JCheckBox and JRadioButton.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight.
Layout Managers Arranges and lays out the GUI components on a container.
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
University of Limerick1 Software Architecture Java Layout Managers.
Lec.10 (Chapter 8 & 9) GUI Jiang (Jen) ZHENG June 27 th, 2005.
CSC 480 Software Engineering Design With Patterns.
3461 Laying Out Components Interior Design for GUIs.
CS 151: Object-Oriented Design October 15 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
Swinging in Your Java Playground. Background Swing is a part of the Java Foundation Classes (JFC). The JFC is made up of features intended to give a programmer.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
AWT Vs SWING. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses.
Chapter 5 Patterns and GUI Programming -Part 1-. Pattern A pattern is a description of a problem and its solution that you can apply to many programming.
Chapter 5 Patterns and GUI Programming -Part 2-. COMPOSITE Pattern Containers and Components Containers collect GUI components Sometimes, want to add.
Starting on GUIs A version of the “Double or Nothing” gui is here:
Chapter 5 Patterns and GUI Programming -Part 2-. STRATEGY Pattern Layout Managers What if we need to specifies pixel position of components when  User.
Pattern and GUI Programming
Graphical User Interfaces
Observer Pattern Context:
Christopher Budo, Davis Nygren, spencer franks, Luke miller
Modern Programming Language Java
Observer Design Pattern
Chap 7. Building Java Graphical User Interfaces
Design Patterns in Swing and AWT
Design Patterns in Swing and AWT
Panels & Layout Managers
CSC 480 Software Engineering
GUI building with the AWT
Border Layout, using Panels, Introduction to PinBallGame
Model, View, Controller design pattern
CSC 480 Software Engineering
Graphical User Interface
Presentation transcript:

1 Object Oriented Design & Patterns Part 1

2 Design Patterns Derived from architectural patterns: –rules for design of buildings –describe common problems, solutions to those problems OO design patterns –convenient way of reusing OO code between projects, programmers –catalog common interactions between objects that programmers have found useful

3 Design Patterns Each pattern includes: –description of problem context –prescription for solution Idea is to distill a design rule into a simple format

4 Example: Iterators An iterator is a method or set of methods applied to an aggregate data structure (such as a linked list) Iterator provides access to structure members without requiring knowledge of internal structure details

5 Iterator Pattern: Context An aggregate object contains element objects Clients need access to the element objects The aggregate object should not expose its internal structure Multiple clients may want independent access

6 Iterator Pattern: Solution Define an iterator that fetches one element at a time Each iterator object keeps track of the position of the next element If there are several aggregate/iterator variations, it is best if the aggregate and iterator classes realize common interface types.

7 Iterator Pattern

8 Iterator pattern example: linked list Design pattern name: Aggregate ConcreteAggregate Iterator ConcreteIterator createIterator() next() isDone() currentItem() Actual name: List LinkedList ListIterator anonymous class implementing ListIterator listIterator() next() opposite of hasNext() return value of hasNext()

9 Model/View/Controller architecture Describes interaction of objects in a user interface with multiple editable views Example: PowerPoint –outline view –slide view –notes view –slide sorter view Edit in one view updates another; seems instantaneous

10 Model/View/Controller architecture Model: data structure, no visual representation (example: array) Views: visual representations –drawn using specific format –for example, number table Vs. bar chart Controllers: user interaction

11 Model/View/Controller architecture Each aspect has discrete responsibilities: –Views/controllers update model –Model tells views that data has changed –Views redraw themselves

12 Model/View/Controller architecture

13 Model/View/Controller architecture Minimizes coupling between models, views & controls –model has no knowledge of views; just knows to notify them of change –views know nothing about controllers –easy to add more views to model –easy to change controller of a view Views are example of Observer pattern

14 Observer Pattern Model notifies views when something interesting happens Button notifies action listeners when something interesting happens Views attach themselves to model in order to be notified Action listeners attach themselves to button in order to be notified Generalize: Observers attach themselves to subject

15 Observer Pattern Context –An object, called the subject, is source of events –One or more observer objects want to be notified when such an event occurs.

16 Observer Pattern Solution –Define an observer interface type. All concrete observers implement it. –The subject maintains a collection of observers. –The subject supplies methods for attaching and detaching observers. –Whenever an event occurs, the subject notifies all observers.

17 Observer Pattern

18 Observer pattern example: Swing buttons Pattern name: Subject Observer ConcreteObserver attach() notify() Actual name: JButton ActionListener ActionListener implementor addActionListener() actionPerformed()

19 Layout Managers User interfaces made up of components Components placed in containers; need to arrange components Swing doesn't use hard-coded pixel coordinates Advantages: –Can switch "look and feel" –Can internationalize strings Layout manager controls arrangement

20 Standard Layout Managers: FlowLayout Components are laid out left to right; when a row is full, a new row is started

21 Standard Layout Managers: BoxLayout Components are laid out left to right or top to bottom

22 Standard Layout Managers: BorderLayout Default layout manager for Jframes Defines 5 areas: Center, North, South, East, West –Don’t have to place a component in every area –Areas are sized according to need of component

23 Standard Layout Managers: BorderLayout

24 Standard Layout Managers: GridLayout Components laid out in grid, all same size

25 Standard Layout Managers: GridBagLayout Complex set of cells contain components Similar to HTML table

26 Using Layout Managers Create container Panel p = new Panel(); Set layout manager p.setLayout(new GridLayout(4,4,3,3)); Add components p.add(darken);

27 Using Layout Managers