Design Patterns in Swing and AWT

Slides:



Advertisements
Similar presentations
15 Copyright © 2005, Oracle. All rights reserved. Adding User Interface Components and Event Handling.
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 (Part IV)
CS18000: Problem Solving and Object-Oriented Programming.
Graphic User Interfaces Layout Managers Event Handling.
Containers and Components 1.Containers collect GUI components 2.Sometimes, want to add a container to another container 3.Container should be a component.
Problem Solving 6 GUIs and Event Handling ICS-201 Introduction to Computing II Semester 071.
TCU CoSc Programming with Java Handling Events.
Things to mention public static void main(String [] args) –The starting point for a free-standing Java application (i.e. one not run from the DrJava interactions.
Object-Oriented Design & Patterns 2 nd edition Cay S. Horstmann Chapter 5: Patterns and GUI Programming CPSC 2100 Software Design and Development 1.
Java Foundation Classes (JFC/Swing) Carl Alphonce revised Spring 2007 (with contributions from Alan Hunt)
OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
JFC/Swing lectures O BSERVER PATTERN – general form Idea: decouple event from event handling Concrete Observable Abstract Observable Concrete Observer.
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.
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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
Design patterns Observer,Strategi, Composite,Template (Chap 5, 6)
CPSC150 JavaLynn Lambert CPSC150 Week 12 InheritanceInterfaces.
1 Object Oriented Design & Patterns Part 1. 2 Design Patterns Derived from architectural patterns: –rules for design of buildings –describe common problems,
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler.
Design Patterns and Graphical User Interfaces Horstmann ,
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Java Swing, Events and MVC Optional Readings: Eckel’s Thinking in Java: Chap 14 (
Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal
Field Trip # 21 Creating PDFs with Java By Keith Lynn.
CSE 219 Patterns in Programming More Design Patterns.
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.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
CS Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /20/2015 GUI - Graphical User Interface.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
CSC 480 Software Engineering Design With Patterns.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Field Trip #22 Creating an Excel Spreadsheet with Java By Keith Lynn.
Swing / Session1 / 1 of 30 Module Introduction Distributed Computing in Java.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
CS 151: Object-Oriented Design October 15 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
Review_6 AWT, Swing, ActionListener, and Graphics.
CS 415 N-Tier Application Development By Umair Ashraf June 25,2013 National University of Computer and Emerging Sciences Lecture # 4 Web Presentation Patterns.
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.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 15 : Swing III King Fahd University of Petroleum & Minerals College of Computer.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Java Swing, Events Readings: Just Java 2: Chap 19 & 21, or Eckel’s Thinking in Java: Chap 14 Slide credits to CMPUT 301, Department of Computing Science.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Developing GUIs With the Eclipse Visual Editor, Swing/AWT Edition David Gallardo.
Introduction to GUI in 1 Graphical User Interface 3 Nouf Almunyif.
1 A Quick Java Swing Tutorial. 2 Introduction Swing – A set of GUI classes –Part of the Java's standard library –Much better than the previous library:
Chapter 6 Building Java GUIs. MVC Model View Controller The model passes its data to the view for rendering The view determines which events are passed.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
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.
A Quick Java Swing Tutorial
Pattern and GUI Programming
Graphical User Interfaces
Observer Pattern Context:
Java GUI.
Advanced GUI Programming
Review: Java GUI Programming
Graphical User Interface (pronounced "gooey")
A Quick Java Swing Tutorial
Ellen Walker Hiram College
Design Patterns in Swing and AWT
<<interface>> Strategy
Introduction to Event Handling
Steps to Creating a GUI Interface
A Quick Java Swing Tutorial
Presentation transcript:

Design Patterns in Swing and AWT Strategy Pattern: LayoutManagers are Strategies Observer Pattern: event listeners are observers Composite Pattern: a container can be placed inside another container just like any component Decorator Pattern: you can "decorate" any component by using JScrollPane to add scroll bars MVC Pattern: JTable gets data from a TableModel Command Pattern: Action objects are commands that are invoked by components (like JButton). The Invoker, the Command, and Receiver (your application logic) are all separate.

LayoutManager - what pattern?

LayoutManager is a Strategy Strategy Pattern Name in Pattern Name in this Example Content Container Strategy LayoutManager Concrete Strategy FlowLayout, GridBagLayout, .. setStrategy setLayout( LayoutManager ) doWork( ) layoutContainer( )

Benefit of LayoutManager What are the benefits of separating LayoutManager from the container classes? Why don't we put the layout code inside each container?

Observer Pattern Name In Observer Pattern Name in Swing graphics Subject Observer Concrete Observer attach( ) notify( )

Observer Pattern Name In Observer Pattern Name in Swing graphics Subject JButton, JMenuItem, JCheckBox Observer ActionListener Concrete Observer your class implementing ActionListener attach( ) addActionListener( observer ) notify( ) actionPerformed( )