Containers and Components 1.Containers collect GUI components 2.Sometimes, want to add a container to another container 3.Container should be a component.

Slides:



Advertisements
Similar presentations
Chapter 6 Objects and Classes F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive data type and.
Advertisements

1 Chapter 8 Objects and Classes Lecture 2 Prepared by Muhanad Alkhalisy.
ECE452/CS446/SE464 Design Patterns: Part I Answers A Tutorial by Peter Kim Based on slides prepared by Krzysztof Pietroszek.
Object-Oriented Design & Patterns 2 nd edition Cay S. Horstmann Chapter 5: Patterns and GUI Programming CPSC 2100 Software Design and Development 1.
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
March Ron McFadyen1 Composite Used to compose objects into tree structures to represent part-whole hierarchies Composite lets clients treat.
Fall 2009ACS-3913 Ron McFadyen Composite Pattern Problem: How do we treat a composition structure of objects the same way as a non-composite object? Arises.
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
1 Patterns & GUI Programming Part 2. 2 Creating a Custom Layout Manager Layout manager determines how components are arranged/displayed in a container.
Java Swing Toolkit Graphics The key to effectively using graphics in Java is understanding: –the basic components of the graphics library –the patterns.
Winter 2015ACS Ron McFadyen1 Composite Pattern A composite is a group of objects in which some objects contain others; one object may represent.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Chapter 5 (Horstmann’s Book) Patterns and GUI Programming Hwajung Lee.
Design patterns Observer,Strategi, Composite,Template (Chap 5, 6)
Graphics without NGP The key to effectively using graphics in Java is understanding: –the basic components of the graphics library –the patterns that are.
More OOP Design Patterns
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
ITEC324 Principle of CS III Chapter 5 (Horstmann’s Book) Patterns and GUI Programming Modified from slides by Dr. Hwajung Lee.
Design Patterns and Graphical User Interfaces Horstmann ,
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
SE2811 Week 7, Class 1 Composite Pattern Applications Conceptual form Class structure Coding Example Lab Thursday: Quiz SE-2811 Slide design: Dr. Mark.
3-1 Composite Design Pattern Rick Mercer. 2 Composite Pattern Context : –Often complex structures are built with container and primitive objects. Container.
Computer Science 209 Introduction to Design Patterns: Iterator Composite Decorator.
Chapter 8. About the Midterm Exam.. Exam on March 12 Monday (Tentatively) Review on March 7 Wednesday Cover from Chapter 6 Grades will be out before spring.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
CS 151: Object-Oriented Design October 24 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
More Design Patterns Horstmann ch.10.1,10.4. Design patterns Structural design patterns –Adapter –Composite –Decorator –Proxy Behavioral design patterns.
IM103 week 11 Part 2 P532 Case Study part 2: the Airport GUI Learning objectives By the end of this lecture you should be able to:  use the JTabbedPane.
CSC 480 Software Engineering Design With Patterns.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
Java GUI. Overview The ”idea” The ”idea” The Components The Components Listeners Listeners The Program The Program Interface Eventlistener Interface Eventlistener.
Graphics in Java Dr. Andrew Wallace PhD BEng(hons) EurIng
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
GUIs Graphical User Interfaces. Everything coming together Known: – Inheritance – Interfaces – Abstract classes – Polymorphism – Exceptions New: – Events.
Computer Science 209 The Adapter Pattern. The Context of the Adapter Pattern I want to use an existing class (the adaptee) without modifying it The context.
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
Computer Science 209 Software Development Inheritance and Composition.
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.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Bridge Bridge is used when we need to decouple an abstraction from its implementation so that the two can vary independently. This type of design pattern.
Decorator Design Pattern Rick Mercer CSC 335: Object-Oriented Programming and Design.
The Decorator Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Decorator Design Pattern Phillip Shin. Overview Problem Solution Example Key points.
1 CSE 331 Composite Layouts; Decorators slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Frame Windows Application program, not applet Construct and show frame JFrame frame = new JFrame(); *** frame.show(); *** Set default close operation..
COMPOSITE PATTERN NOTES. The Composite pattern l Intent Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients.
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
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.
Chapter 5 Patterns and GUI Programming. Pattern A pattern is a description of a problem and its solution that you can apply to many programming situation.
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
Observer Pattern Context:
Slide design: Dr. Mark L. Hornick
Java Programming: From Problem Analysis to Program Design,
Composite Pattern SE2811 Software Component Design
Design Patterns in Swing and AWT
Design Patterns in Swing and AWT
Composite Pattern Context:
08/15/09 Decorator Pattern Context: We want to enhance the behavior of a class, and there may be many (open-ended) ways of enhancing the class. The enhanced.
Advanced Programming in Java
13. Composite Pattern SE2811 Software Component Design
13. Composite Pattern SE2811 Software Component Design
16. Visitors SE2811 Software Component Design
Activity 1 - Chapter 5 -.
Presentation transcript:

Containers and Components 1.Containers collect GUI components 2.Sometimes, want to add a container to another container 3.Container should be a component 4.Composite design pattern 5.Composite method typically invoke component methods 6.E.g. Container.getPreferredSize invokes getPreferredSize of components Consider an Example : p1.add(b1); // Add Button b1 to Japnel p1 p1.add(b2); // Add Button b2 to Japnel p1 p1.add(b3); // Add Button b3 to Japnel p1 C1.add(p1) // Add method will be invoked on all primitive objects. b1,b2,b3 -  Primitive objects p1 -  Composite Object

Composite Pattern Context Primitive objects can be combined to composite objects Clients treat a composite object as a primitive object Interface for composite object and primitive object should be same

Solution 1.Define an interface type that is an abstraction for the primitive objects 2.Composite object collects primitive objects 3.Composite and primitive classes implement same interface type. 4.When implementing a method from the interface type, the composite class applies the method to its primitive objects and combines the results JButtonJPanel, JFrame

Name in Design PatternActual Name (AWT components) PrimitiveComponent CompositeContainer Leafa component without children (e.g. JButton) method()a method of Component (e.g. getPreferredSize)

Scroll Bars 1.Scroll Bars can be added to components to display more information that can be shown on screen. 2.Adding a Scroll bar JTextArea area = new JTextArea(10,25); JScrollPane scroller = new JScrollPane(area); 3. Scroll bars adds/enhances functionality to the underlying component. 4. Adding/Enhancing Functionality is called Decoration. 5. JScrollPane Decorates a Component and is again a Component.

Decorator Pattern Context 1.Component objects can be decorated (visually or behaviorally enhanced) 2.The decorated object can be used in the same way as the undecorated object 3.The component class does not want to take on the responsibility of the decoration 4.There may be an open-ended set of possible decorations Solution 1.Define an interface type that is an abstraction for the component 2.Concrete component classes realize this interface type. 3.Decorator classes also realize this interface type. 4.A decorator object manages the component object that it decorates 5.When implementing a method from the component interface type, the decorator class applies the method to the decorated component and combines the result with the effect of the decoration.

Name in Design PatternActual Name (scroll bars) Component ConcreteComponentJTextArea DecoratorJScrollPane method()a method of Component (e.g. paint)

Example Line Item Interface public interface LineItem { double getPrice(); String toString(); } class Product implements LineItem { private String description; private double price; Product(String description, double price) { this.description = description; this.price = price; } public double getPrice() { return price;} public String toString() { return descrition ;} } Primitive Object Composite Object

import java.util.*; public class Bundle implements LineItem { private ArrayList items; public Bundle() { items = new ArrayList (); } public void add(LineItem item) { items.add(item); } public double getPrice() { double price = 0; for (LineItem item : items) price += item.getPrice(); return price; } public String toString() { String description = "Bundle: "; for (int i = 0; i < items.size(); i++) { if (i > 0) description += ", "; description += items.get(i).toString(); } return description; } }