Chapter 5 Patterns and GUI Programming -Part 2-. STRATEGY Pattern Layout Managers What if we need to specifies pixel position of components when  User.

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

Graphical User Interfaces
Java Software Development Paradigm Lecture # 12. Basics of GUI.
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.
Corresponds with Chapter 12
1 Patterns & GUI Programming Part 2. 2 Creating a Custom Layout Manager Layout manager determines how components are arranged/displayed in a container.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Understanding SWING Architecture CS 4170 UI Design Hrvoje Benko Oct. 9, 2001.
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)
1 Object Oriented Design & Patterns Part 1. 2 Design Patterns Derived from architectural patterns: –rules for design of buildings –describe common problems,
Contructing GUI’s in Java Implemented in the Swing API Imported into your programs by: import javax.swing.*; Most Swing programs also need the AWT packages.
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 ,
Computer Science 209 The Strategy Pattern I: Comparisons and Layouts.
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.
Layout Management Containers can arrange their components. Our container is a JPanel, and it can set the way it’s components will be laid out : mypanel.setLayout.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
CSE 219 Computer Science III Graphical User Interface.
Introduction to GUI in Java 1. Graphical User Interface Java is equipped with many powerful,easy to use GUI component such as input and output dialog.
Adding Graphics to a Frame Application Applets: Can generate drawings by overriding paint Frame: Do not draw directly on a frame. Draw graphics on a JPanel.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
1 Why layout managers Can we perform layout without them? –Yes. A container’s layout property can be set to null. Absolute positioning: specify size and.
10/24/20151 Java GUI Programming. 10/24/20152 What is a GUI? Java has standard packages for creating custom Graphical User Interfaces Some of the fundamental.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight.
CompSci 100E 35.1 Graphical User Interfaces: GUIs  Components  Flat Layouts  Hierarchical Layouts  Designing a GUI  Coding a GUI.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Layout Managers Arranges and lays out the GUI components on a container.
Layout Manager Summary
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.
GUI Basics. What is GUI? A graphical user interface (GUI) is a type of user interface item that allows people to interact with programs in more ways than.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
3461 Laying Out Components Interior Design for GUIs.
Java layout managers. import java.awt.*; import java.awt.event.*; import javax.swing.*; class ButtonPanel extends JPanel implements ActionListener { public.
Basics of GUI Programming Chapter 11 and Chapter 22.
J McQuillanSE204:2004/2005: Lecture 3Slide 1 Specialised Components Can create specialised components. Do this by subclassing the component that you are.
Lab 4: GUIs, Panels, Mouse and Key Listeners ICOM4015: FALL 2014 A N I NTRODUCTION TO P ANELS AND L AYOUTS CREATED BY KATYA I. BORGOS REVISED BY AMIR H.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
CSI 3125, Preliminaries, page 1 Layout Managers. CSI 3125, Preliminaries, page 2 Layout Managers The LayoutManagers are used to arrange components in.
Java Swing - Lecture 3 Layout Management
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
CSC 205 Programming II Lecture 7 AWT – Event Handling & Layout.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
Dept. of CSIE, National University of Tainan 10/21/2012 Arranging Components on a User Interface.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
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 7 A First Look at GUI Applications Layout Managers.
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.
Pattern and GUI Programming
Graphical User Interfaces
Christopher Budo, Davis Nygren, spencer franks, Luke miller
Swing JComponents.
Modern Programming Language Java
University of Central Florida COP 3330 Object Oriented Programming
Tim McKenna Layout Mangers in Java Tim McKenna
Chap 7. Building Java Graphical User Interfaces
Containers and Components
Tim McKenna Layout Mangers in Java Tim McKenna
Creating Graphical User Interfaces
Panels & Layout Managers
<<interface>> Strategy
GUI Layouts By: Leonard & Saif.
Advanced GUIs and Graphics
Graphical User Interface
Presentation transcript:

Chapter 5 Patterns and GUI Programming -Part 2-

STRATEGY Pattern Layout Managers What if we need to specifies pixel position of components when  User interfaces are made up of use interface components  Components are placed in containers Swing doesn't use hard-coded pixel coordinates for each component.  Advantages: Can switch between various "look and feel" Can internationalize strings Layout manager arranges the components in a container.

STRATEGY Pattern Layout Managers FlowLayout: left to right, start new row when full BoxLayout: left to right or top to bottom BorderLayout: 5 areas, Center, North, South, East, West GridLayout: grid, all components have same size GridBagLayout: the rows & columns can have different sizes and components can span multiple rows and columns

STRATEGY Pattern Layout Managers

Panel  Set layout manager JPanel keyPanel = new JPanel(); keyPanel.setLayout(new GridLayout(4, 3));  Add components for (int i = 0; i < 12; i++) { keyPanel.add(button[i]); } //end for

STRATEGY Pattern Layout Managers

STRATEGY Pattern (Ex) Voice Mail System GUI Same backend as text-based system Only Telephone class changes Buttons for keypad Text areas for microphone, speaker

STRATEGY Pattern (Ex) Voice Mail System GUI

Panel with BorderLayout for speaker JPanel speakerPanel = new JPanel(); speakerPanel.setLayout(new BorderLayout()); speakerPanel.add(new JLabel("Speaker:"), BorderLayout.NORTH); speakerField = new JTextArea(10, 25); speakerPanel.add(speakerField, BorderLayout.CENTER); Laying out the microphone Component

STRATEGY Pattern (Ex) Voice Mail System GUI Arrange keys in panel with GridLayout: JPanel keyPanel = new JPanel(); keyPanel.setLayout(new GridLayout(4, 3)); for (int i = 0; i < 12; i++) { JButton keyButton = new JButton(...); keyPanel.add(keyButton); keyButton.addActionListener(...); }

STRATEGY Pattern (Ex) Voice Mail System GUI Put speaker, keypads, and microphone panel into content pane Content pane already has BorderLayout Ch5/mailgui/Telephone.java

STRATEGY Pattern (Ex) Custom Layout Manager Odd-numbered components right aligned Even-numbered components left aligned Implement LayoutManager interface type

STRATEGY Pattern The LayoutManager Interface Type public interface LayoutManager { Dimension minimumLayoutSize(Container parent); Dimension preferredLayoutSize(Container parent); void layoutContainer(Container parent); void addLayoutComponent(String name, Component comp); void removeLayoutComponent(Component comp); }

STRATEGY Pattern Form Layout Ch5/layout/FormLayout.java Ch5/layout/FormLayoutTester.java Ch5/layout/FormLayoutTester.java

STRATEGY Pattern The STRATEGY pattern teaches how to supply variants of an algorithm Other manifestation: Comparators Comparator comp = new CountryComparatorByName(); Collections.sort(countries, comp);

STRATEGY Pattern Context 1.A class (called context class) can benefit from different variants for an algorithm 2.Clients of the context class sometimes want to supply custom versions of the algorithm Solution 1.Define an interface type that is an abstraction for the algorithm. We’ll call this interface type the strategy. 2.Concrete strategy classes implement the strategy interface type. Each strategy class implements a version of the algorithm. 3.The client supplies a concrete strategy object to the context class. 4.Whenever the algorithm needs to be executed, the context class calls the appropriate methods of the strategy object.

STRATEGY Pattern

Name in Design PatternActual Name ContextContainer StrategyLayoutManager ConcreteStrategyA layout manager such as BolderLayout doWork()A method of the LayoutManager interface type such as layoutContainer