Design Patterns Taxonomy. Structural Patterns. An Example Application. Lets Look at some Code!

Similar documents
GUI Event-Driven Programming

Programming with Java GUI components

GUIs with Swing. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2012

Fondamenti di Java. Introduzione alla costruzione di GUI (graphic user interface)

VAASAN AMMATTIKORKEAKOULU UNIVERSITY OF APPLIED SCIENCES. Xiaoling Yu IMPLEMENTATION OF A SECURE SHELL FILE TRANSFER PROGRAM IN JAVA

5.17 GUI. Xiaoyi Jiang Informatik I Grundlagen der Programmierung

Konzepte objektorientierter Programmierung


Formulas, Functions and Charts

Implementação. Interfaces Pessoa Máquina 2010/ Salvador Abreu baseado em material Alan Dix. Thursday, June 2, 2011

The Basic Java Applet and JApplet

Principles of Software Construction: Objects, Design and Concurrency. GUIs with Swing. toad Spring 2013

MAKE A NEW SUBSITE 1. On the left navigation, click Site Contents (or Sites). Scroll down to subsites. Click new subsite.

Extending Desktop Applications to the Web

Assignment # 2: Design Patterns and GUIs

GUI Components: Part 2

Using the SAS Enterprise Guide (Version 4.2)

An Introduction to Excel Pivot Tables

CSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus

Event processing in Java: what happens when you click?

Gadget: A Tool for Extracting the Dynamic Structure of Java Programs

north seattle community college

Vodafone PC SMS (Software version 4.7.1) User Manual

How Scala Improved Our Java

Mouse Event Handling (cont.)

How To Use The Command Pattern In Java.Com (Programming) To Create A Program That Is Atomic And Is Not A Command Pattern (Programmer)

3. Mathematical Induction

Doña Ana County, NM Interactive Zoning Map

Computer Training Centre University College Cork. Excel 2013 The Quick Analysis Tool

8.2. Solution by Inverse Matrix Method. Introduction. Prerequisites. Learning Outcomes

Module 9. User Interface Design. Version 2 CSE IIT, Kharagpur

Introduction to Measurement Tools

Swing. A Quick Tutorial on Programming Swing Applications

The Abstract Windowing Toolkit. Java Foundation Classes. Swing. In April 1997, JavaSoft announced the Java Foundation Classes (JFC).

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

Essentials of the Java(TM) Programming Language, Part 1

Regular Expressions and Automata using Haskell

During the process of creating ColorSwitch, you will learn how to do these tasks:

Text Basics. Introduction

West Virginia University College of Engineering and Mineral Resources. Computer Engineering 313 Spring 2010

Windows Live Movie Maker Tutorial

Microsoft Excel 2013 Splitting Windows and Fixing Panes (Level 3)

Use signatures in Outlook 2010

This activity will show you how to draw graphs of algebraic functions in Excel.

Automated Data Collection for Usability Evaluation in Early Stages of Application Development

This activity will guide you to create formulas and use some of the built-in math functions in EXCEL.

Microsoft PowerPoint 2011

If there is not a Data Analysis option under the DATA menu, you will need to install the Data Analysis ToolPak as an add-in for Microsoft Excel.

What is Microsoft Excel?

D06 PROGRAMMING with JAVA

Model-View-Controller (MVC) Design Pattern

9.4. The Scalar Product. Introduction. Prerequisites. Learning Style. Learning Outcomes

Using Excel for inferential statistics

Spotfire v6 New Features. TIBCO Spotfire Delta Training Jumpstart

Quick Start Guide Simple steps for editing and manipulating your photo.

Q&As: Microsoft Excel 2013: Chapter 2

Adobe Acrobat X Pro Creating & Working with PDF Documents

Avaya one-x Agent quick reference

Paper Designing Web Applications: Lessons from SAS User Interface Analysts Todd Barlow, SAS Institute Inc., Cary, NC

Microsoft PowerPoint Exercises 4

Excel Formulas & Graphs

Excel Using Pivot Tables

Syllabus for CS 134 Java Programming

Practice Fusion API Client Installation Guide for Windows

Creating a PowerPoint Poster using Windows

Microsoft Excel 2010

HOW TO MAKE A TABLE OF CONTENTS

Data Visualization. Prepared by Francisco Olivera, Ph.D., Srikanth Koka Department of Civil Engineering Texas A&M University February 2004

Microsoft PowerPoint 2010

Specialized Android APP Development Program with Java (SAADPJ) Duration 2 months

How to send meeting invitations using Office365 Calendar

Excel Using Pivot Tables

Connecting Your Camera under Windows XP

Microsoft Access Basics

Scan Physical Inventory


Online Sharing User Manual

Lecture 7: Java RMI. CS178: Programming Parallel and Distributed Systems. February 14, 2001 Steven P. Reiss

GAMBIT Demo Tutorial

1. Starting With Windows Live Essentials

Converting from Netscape Messenger to Mozilla Thunderbird

FedTraveler.com. Log o FedTraveler.com using your valid Member ID and PIN.

Excel Integrated Reporting

Using MS Excel to Analyze Data: A Tutorial

Explore Oakville How To Perform a Search and Navigate a Map

Computer Training. NR Computer Learning Center 1835 W. Orangewood Ave #200 Orange CA 92868

CHAPTER 14 Understanding an App s Architecture

BI 4.1 Quick Start Guide

Fig.1 Electoronic whiteboard and programming education system

Introduction To Microsoft Office PowerPoint Bob Booth July 2008 AP-PPT5

To add a data form to excel - you need to have the insert form table active - to make it active and add it to excel do the following:

Seventeen. Chapter. Pavlov: Where PBD Meets Macromedia s Director. David Wolber. University of San Francisco S R L

About Entering Donations in QuickBooks

Introduction To Microsoft Office Excel Bob Booth July 2008 AP-Excel8

ACADEMIC TECHNOLOGY SUPPORT

CS 335 Lecture 06 Java Programming GUI and Swing

Geometer s Sketchpad. Discovering the incenter of a triangle

The Center for Teaching, Learning, & Technology

Content Author's Reference and Cookbook

2 SYSTEM DESCRIPTION TECHNIQUES

Transcription:

Design Patterns Taxonomy Creational patterns Concern the process of object creation Structural patterns Deal with the composition of classes or objects Behavioral patterns Characterize the ways in which classes or objects interact and distribute responsibility Structural Patterns 1 2 An Example Application Lets Look at some Code! Lets create a simple Java program that allows you to enter names into a list, and then select some of those names to be transferred to another list. Our initial list consists of a class roster and the second list, those who will be doing advanced work. In the example UI, You enter names into the top entry field and click on Insert to move the names into the left-hand list box. To move names to the right-hand list box, you click on them, and then click on Add. To remove a name from the right hand list box, click on it and then on Remove. This moves the name back to the left-hand list. The code will consist of a GUI creation constructor and an actionlistener routine for the three buttons: 3 4

ActionListener ActionEvent public interface ActionListener extends EventListener The listener interface for receiving action events. The class that is interested in processing an action event implements this interface, and the object created with that class is registered with a component, using the component's addactionlistener method. When the action event occurs, that object's actionperformed method is invoked. public class ActionEvent extends AWTEvent A semantic event which indicates that a component-defined action occurred. This high-level event is generated by a component (such as a Button) when the component-specific action occurs (such as being pressed). The event is passed to every ActionListener object that registered to receive such events using the component's addactionlistener method. The object that implements the ActionListener interface gets this ActionEvent when the event occurs. The listener is therefore spared the details of processing individual mouse movements and mouse clicks, and can instead process a "meaningful" (semantic) event like "button pressed". java.lang.object java.util.eventobject java.awt.awtevent java.awt.event.actionevent 5 6 getsource() addname() Method inherited from class java.util.eventobject public Object getsource() Returns: The object on which the Event initially occurred. add() is a method of AWT List class. 7 8

movenameright() and movenameleft() AWT List class 9 10 Code Maintenance Task A Possible Solution Suppose you would like to rewrite the program using the Java Foundation Classes (JFC or Swing ). Most of the methods you use for creating and manipulating the user interface remain the same. However, the JFC JList class is markedly different than the AWT List class. In fact, because the JList class was designed to represent far more complex kinds of lists, there are virtually no methods in common between the classes. Both classes (AWT List class, JFC JList class) have quite a number of other methods and almost none of them are closely correlated. However, since we have already written the program once, and make use of two different list boxes, writing some auxiliary code to make the JList class look like the List class seems a sensible solution to our problem. 11 12

More on JList Our Task is Much Simpler! The JList class is a window container which has an array, vector or other ListModel class associated with it. It is this ListModel that actually contains and manipulates the data. The JList class does not contain a scroll bar, but instead relies on being inserted in the viewport of the JScrollPane class. Data in the JList class and its associated ListModel are not limited to strings, but may be almost any kind of objects, as long as you provide the cell drawing routine for them. This makes it possible to have list boxes with pictures illustrating each choice in the list. We are only going to create a class that emulates the List class, and that in this simple case, needs only the three methods: add(string); remove(string); String[] getselecteditems() We define the needed methods as an interface and then make sure that the class we create implements those methods: 13 14 JScrollPane We create a class that contains a JList class but which implements the methods of the awtlist interface. This is a pretty good choice here, because the outer container for a JList is not the list element at all, but the JScrollPane that encloses it. 15 16

JListData Note that the actual data handling takes place in the JListData class. This class is derived from the AbstractListModel, which defines the following methods: 17 18 Fire? Final Touches The three fire methods are the communication path between the data stored in the ListModel and the actual displayed list data. Firing them causes the displayed list to be updated. Hence, Each time we add data to the data vector, we call the fireintervaladded method to tell the list display to refresh that area of the displayed list. 19 20

CMSC 433 Programming Language Technologies and Paradigms Spring 2007 Adapter Pattern Mar. 27, 2007 What is it? The Adapter pattern is used to convert the programming interface of one class into that of another. We use adapters whenever we want unrelated classes to work together in a single program. The concept of an adapter is thus pretty simple; we write a class that has the desired interface and then make it communicate with the class that has a different interface. 21 22 Two-way Adapter Pluggable Adapter The two-way adapter is a clever concept that allows an object to be viewed by different classes as being either of type X or a type Y. A pluggable adapter is one that adapts dynamically to one of several classes. Of course, the adapter can only adapt to classes it can recognize, and usually the adapter decides which class it is adapting. 23 24

Reflection Fine Print Java has yet another way for adapters to recognize which of several classes it must adapt to: reflection. You can use reflection to discover the names of public methods and their parameters for any class. For example, for any arbitrary object you can use the getclass() method to obtain its class and the getmethods() method to obtain an array of the method names. A method dump like the one produced by the code shown in the previous slide can generate a very large list of methods. It is easier if you know the name of the method you are looking for and simply want to find out which arguments that method requires. From that method signature, you can then deduce the adapting you need to carry out. 25 26