Software Construction

Size: px
Start display at page:

Download "Software Construction"

Transcription

1 Lecture 11: Command Design Pattern Software Construction in Java for HSE Moscow Tom Verhoeff Eindhoven University of Technology Department of Mathematics & Computer Science Software Engineering & Technology Group wstomv/edu/sc-hse c 2013, T. TUE.NL 1/27 Software Construction: Lecture 11

2 Overview Feedback on Series 10 Organization of GUI application: Model View Controller Menus and Graphics in a Java GUI Command Design Pattern: Do, Undo, Redo c 2013, T. TUE.NL 2/27 Software Construction: Lecture 11

3 Feedback on Simple Kakuro Helper 1 & 2 Simple Kakuro Helper : Much better: only 2 Rejected Rejected work must be improved; see FAQ Simple Kakuro Helper 2: Only 18 students obtain max score Try to improve performance: maxnumber = 30 must run 10 s c 2013, T. TUE.NL 3/27 Software Construction: Lecture 11

4 Feedback on Testing of KakuroCombinationGenerator (a) Why is it not a good idea to include unnecessary test cases? Costs extra test development time. Gives false impression of application code quality. Gives false impression of test quality. Costs extra test time when executing tests. Adds to the maintenance burden. c 2013, T. TUE.NL 4/27 Software Construction: Lecture 11

5 Feedback on Testing of KakuroCombinationGenerator (b) What would be the consequences for testing of generate(int, int) in KakuroCombinationGenerator, when the postcondition would be weakened by dropping the requirement of lexicographic order? That is, when method generate() would be allowed to generate combinations in any order. Concern With lex. order Without lex. order No missing Count, and compare with expected count No duplicates Compare with previous Store all and compare Order Compare with previous Not a concern Cost Keep track of previous Keep track of all c 2013, T. TUE.NL 5/27 Software Construction: Lecture 11

6 Feedback on Testing of KakuroCombinationGenerator (b) Checking lexicographic order is easy: one extra variable preceding in inner class Checker Checking for no duplicates is easy with order: Compare to preceding Checking for no duplicates is harder without order: Store all combinations, and search among stored Note: Lexicographic order was imposed on purpose to ease testing. c 2013, T. TUE.NL 6/27 Software Construction: Lecture 11

7 How to Organize GUI Code Separation of Concerns (decoupling): Problem-related data: Model E.g.: Abstract (mathematical) Kakuro puzzle state: cell contents Look, custom graphical output: View E.g.: Visualization of Kakuro puzzle state Feel, custom input handling: Control E.g.: Handle menu items, mouse clicks in cells, etc. c 2013, T. TUE.NL 7/27 Software Construction: Lecture 11

8 Model View Controller (MVC) Architecture Controller UI events User <<interacts>> Legend direct dependency, use, call commands commands queries View View View indirect dependency, callback Model change events c 2013, T. TUE.NL 8/27 Software Construction: Lecture 11

9 Menus and File Choosers See tutorial under Downloads For common aspects of buttons and menu items, see Eck Ch.13.3 Action and AbstractAction c 2013, T. TUE.NL 9/27 Software Construction: Lecture 11

10 Graphics in Java using Swing A component paints itself via its paintcomponent(graphics g). This method is called automatically whenever needed. (It is called by paint(), which itself is a callback method.) Via repaint(), the application can request a paint() call. There is no guarantee when this is request will be honored. Multiple repaint requests may get merged into one update. Override paintcomponent() to replace the default paint behavior. The new definition must first call super.paintcomponent(g). Graphics g is used for drawing: g.drawxxx(...). JFrame uses paint() instead of paintcomponent(). However, it is not recommended to override its paint() method. Instead, draw on a component (like a JPanel) inside the frame. c 2013, T. TUE.NL 10/27 Software Construction: Lecture 11

11 Graphics in Java using Swing There are various ways to show application-specific graphics. 1. paintcomponent() redraws the graphics from scratch. con pro Everything must be redrawn, in every call. Can be slow. Needs to store data to redraw the graphics. No need to undraw : easy to delete something. Terminology: Graphics shows a view of an abstract model. 2. Draw in a buffer and show it by paintcomponent(). con pro Must set up buffer; must undraw to delete something. No need to redraw everything; only draw the changes. Example: GraphicsExample, takes approach 1 c 2013, T. TUE.NL 11/27 Software Construction: Lecture 11

12 Simple Graphics on a JPanel in NetBeans 1. In Design mode, right-click on the JPanel, select Customize Code 2. Under Initialization code change default code custom creation jpanel1 = new javax.swing.jpanel(); jpanel1 = new javax.swing.jpanel() public void paintcomponent(graphics g) { super.paintcomponent(g); paintpanel1(this, g); } } ; 3. In Source mode, add the following code to the frame: private void paintpanel1(javax.swing.jpanel p, Graphics g) {... } c 2013, T. TUE.NL 12/27 Software Construction: Lecture 11

13 Complex Graphics on a JPanel in NetBeans 1. Create a new JPanel descendant via File > New File... > Swing GUI Forms > JPanel Form name it XxxPanel and put it in the gui package. This adds a.java and related.form file to the project. NetBeans controls the Generated Code. 2. In Design mode of the main frame, drag-and-drop XxxPanel from the NetBeans Navigator onto your JFrame. 3. In Source mode of the panel, define the data needed to render the view, and override void paintcomponent(). c 2013, T. TUE.NL 13/27 Software Construction: Lecture 11

14 Undo-Redo Facility User invokes commands via GUI, changing data in models: Do Various degrees of Undo : Undo last (one level of undo) Limited undo (fixed number of levels) Arbitrary undo (limited by memory only) Various degrees of Redo : Not available Redo last (one level of redo) Limited redo (fixed number of levels) Arbitrary redo (limited by memory only) c 2013, T. TUE.NL 14/27 Software Construction: Lecture 11

15 Implement Undo-Redo by Storing Full Model States Store full model state before executing an undoable command Organize stored states as a stack Undo: Pop state from undo stack; restore model to popped state Redo: Use a second stack for undone model states Model needs ability to clone, and to restore a given state Pro: Simple Con: Performance loss when state is large c 2013, T. TUE.NL 15/27 Software Construction: Lecture 11

16 Implement Undo-Redo by Storing State-changing Commands User invokes commands via GUI, changing data in models: Do. These commands can be executed right away, by calling methods. It can be useful to have the ability to call these methods later : command queuing, transaction recovery, redo after undo. Undo : use a stack of done commands. Redo : use a second stack of undone-but-redoable commands. Pro: Stores only information to change state ( deltas ) Con: Needs objects to store commands (Command pattern) c 2013, T. TUE.NL 16/27 Software Construction: Lecture 11

17 Command Design Pattern Command class encapsulates all data to call a method elsewhere: which method to call, including in which object: Receiver which actual parameters to supply as arguments what to do with the return value Offers method to execute the call, optionally to undo the call A command object can be created by one class: Client stored in another class executed (and optionally undone) in yet another class: Invoker Command Design Pattern decouples call data and call moment. c 2013, T. TUE.NL 17/27 Software Construction: Lecture 11

18 Command Design Pattern: Class Diagram Client Invoker «interface» Command execute() undo() Receiver Concrete Command Concrete Command' action() execute() undo() execute() undo() c 2013, T. TUE.NL 18/27 Software Construction: Lecture 11

19 Command Design Pattern: Sequence Diagram : Client r: Receiver : Invoker create(r) c: Concrete Command setcommand(c) action() execute() c 2013, T. TUE.NL 19/27 Software Construction: Lecture 11

20 Undo via Command Pattern Provide each concrete Command with an undo method to revert the effect of execute. It can be necessary to equip the model with extra operations. Introduce a command stack : Stack<Command> undostack; The Controller creates Command objects, executes them, and pushes them onto undostack. Undo is implemented by popping a command from undostack, and invoking its undo method. See: example NetBeans project CommandPattern c 2013, T. TUE.NL 20/27 Software Construction: Lecture 11

21 Redo via Command Pattern Introduce another command stack : Stack<Command> redostack; The Controller creates Command objects, executes them, pushes them on undostack, and clears redostack. Undo is implemented by popping a command from the stack, invoking its undo method, and pushing it onto redostack. Redo is implemented by popping a command from redostack, invoking its execute method, and pushing it onto undostack. Concern: Ensure precondition of method executed by a command c 2013, T. TUE.NL 21/27 Software Construction: Lecture 11

22 Encapsulate Undo-Redo Facilities In example CommandPattern: Undo incorporated into Controller Better: Encapsulate Undo-Redo in separate class Representation: Stack<Command> undostack, redostack Preserve rep invariant for undostack and redostack Commands on undostack have been executed and can be undone Commands on redostack are unexecuted and can be re-executed Operations: did(command), undo(), redo(), etc. c 2013, T. TUE.NL 22/27 Software Construction: Lecture 11

23 Compound Commands A compound command consists of a sequence of commands. Contained commands can be compound: nesting, hierarchy It can be defined via the Composite Pattern. It does not need a receiver. It provides an add method to add commands. Its execute method executes the contained commands, in order. Its undo method undoes the contained commands, in reverse order. c 2013, T. TUE.NL 23/27 Software Construction: Lecture 11

24 Compound Command Design Pattern: Class Diagram Client Invoker «interface» Command execute() undo() 0..* list { ordered } Receiver action() Concrete Command execute() undo() Concrete Command' execute() undo() Compound Command execute() undo() 0..1 c 2013, T. TUE.NL 24/27 Software Construction: Lecture 11

25 Backtracking Speculative technique to search through a state space. Recursive implementation for Loop Puzzle Assistant: 1. Find an undetermined edge e. 2. For each possible edge state s, set e to s, apply strategies, and if state still valid, solve remainder recursively. Implementation variations: Copy entire state (onto the stack) for each recursive call. Undo is automatic by falling back to earlier stored state. Maintain state in global variable, and modify it: do-undo. Here, the Command Pattern can be used. c 2013, T. TUE.NL 25/27 Software Construction: Lecture 11

26 Homework Series 11 Inspect peach 3 feedback on Simple Kakuro Helper 2 Modify CommandPattern demo program to include Redo Modify Kakuro Puzzle Assistant to include Undo/Redo c 2013, T. TUE.NL 26/27 Software Construction: Lecture 11

27 Summary Also see Wikipedia: en.wikipedia.org/wiki/command_pattern The Command design pattern provides a way of capturing the data needed to call a method later elsewhere ( Do facility). Can be extended to offer an Undo facility, optionally with Redo. See example NetBeans project CommandPattern. Backtracking can be based on a Do-Undo mechanism. c 2013, T. TUE.NL 27/27 Software Construction: Lecture 11

2IP15 Programming Methods

2IP15 Programming Methods Lecture 5: Iteration Abstraction 2IP15 Programming Methods From Small to Large Programs Tom Verhoeff Eindhoven University of Technology Department of Mathematics & Computer Science Software Engineering

More information

EINDHOVEN UNIVERSITY OF TECHNOLOGY

EINDHOVEN UNIVERSITY OF TECHNOLOGY EINDHOVEN UNIVERSITY OF TECHNOLOGY Department of Mathematics & Computer Science Exam Programming Methods, 2IP15, Wednesday 17 April 2013, 09:00 12:00 TU/e THIS IS THE EXAMINER S COPY WITH (POSSIBLY INCOMPLETE)

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Kevin Zatloukal Summer 2017 Java Graphics and GUIs (Based on slides by Mike Ernst, Dan Grossman, David Notkin, Hal Perkins, Zach Tatlock) Review: how to create

More information

Software Construction

Software Construction Lecture 7: Type Hierarchy, Iteration Abstraction Software Construction in Java for HSE Moscow Tom Verhoeff Eindhoven University of Technology Department of Mathematics & Computer Science Software Engineering

More information

Object-Oriented Programming Design. Topic : Graphics Programming GUI Part I

Object-Oriented Programming Design. Topic : Graphics Programming GUI Part I Electrical and Computer Engineering Object-Oriented Topic : Graphics GUI Part I Maj Joel Young Joel.Young@afit.edu 15-Sep-03 Maj Joel Young A Brief History Lesson AWT Abstract Window Toolkit Implemented

More information

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI Statics and GUI Dynamics 2 Statics: what s drawn on the screen Components buttons, labels, lists, sliders, menus,... Containers: components that contain

More information

Software Construction

Software Construction Lecture 1: Introduction Software Construction in Java for HSE Moscow Tom Verhoeff Eindhoven University of Technology Department of Mathematics & Computer Science Software Engineering & Technology Group

More information

2IS45 Programming

2IS45 Programming Course Website Assignment Goals 2IS45 Programming http://www.win.tue.nl/~wsinswan/programmeren_2is45/ Rectangles Learn to use existing Abstract Data Types based on their contract (class Rectangle in Rectangle.

More information

2IP15 Programming Methods

2IP15 Programming Methods Lecture 13: Concurrency 2IP15 Programming Methods From Small to Large Programs Tom Verhoeff Eindhoven University of Technology Department of Mathematics & Computer Science Software Engineering & Technology

More information

Undo. principles, concepts, and Java implementation. Checkpointing. Undo Benefits. A manual undo method. Consider a video game

Undo. principles, concepts, and Java implementation. Checkpointing. Undo Benefits. A manual undo method. Consider a video game Undo principles, concepts, and Java implementation Checkpointing A manual undo method - you save the current state so you can rollback later (if needed) Consider a video game - You kill a monster - You

More information

Object Orientated Programming in Java. Benjamin Kenwright

Object Orientated Programming in Java. Benjamin Kenwright Graphics Object Orientated Programming in Java Benjamin Kenwright Outline Essential Graphical Principals JFrame Window (Popup Windows) Extending JFrame Drawing from paintcomponent Drawing images/text/graphics

More information

Software Construction

Software Construction Lecture 2: Decomposition and Java Methods Software Construction in Java for HSE Moscow Tom Verhoeff Eindhoven University of Technology Department of Mathematics & Computer Science Software Engineering

More information

Inheritance. One class inherits from another if it describes a specialized subset of objects Terminology:

Inheritance. One class inherits from another if it describes a specialized subset of objects Terminology: Inheritance 1 Inheritance One class inherits from another if it describes a specialized subset of objects Terminology: the class that inherits is called a child class or subclass the class that is inherited

More information

Undo. principles, concepts Java implementation. Undo 1

Undo. principles, concepts Java implementation. Undo 1 Undo principles, concepts Java implementation Undo 1 Undo* Benefits Undo enables exploratory learning - One of the key claims of direct manipulation is that users would learn primarily by trying manipulations

More information

Prototyping a Swing Interface with the Netbeans IDE GUI Editor

Prototyping a Swing Interface with the Netbeans IDE GUI Editor Prototyping a Swing Interface with the Netbeans IDE GUI Editor Netbeans provides an environment for creating Java applications including a module for GUI design. Here we assume that we have some existing

More information

Android Tutorials. RCH 1:30 (120) MC 3:30 (66) Note: Good advice is to try the RCH session, as the MC 4060 room is small

Android Tutorials. RCH 1:30 (120) MC 3:30 (66) Note: Good advice is to try the RCH session, as the MC 4060 room is small Android Tutorials RCH 207 @ 1:30 (120) MC 4060 @ 3:30 (66) Note: Good advice is to try the RCH session, as the MC 4060 room is small Undo 2 Most Basic Undo Manual undo without programmer Consider a video

More information

Strategy Pattern. What is it?

Strategy Pattern. What is it? Strategy Pattern 1 What is it? The Strategy pattern is much like the State pattern in outline, but a little different in intent. The Strategy pattern consists of a number of related algorithms encapsulated

More information

Command Pattern. CS356 Object-Oriented Design and Programming November 13, 2014

Command Pattern. CS356 Object-Oriented Design and Programming   November 13, 2014 Command Pattern CS356 Object-Oriented Design and Programming http://cs356.yusun.io November 13, 2014 Yu Sun, Ph.D. http://yusun.io yusun@csupomona.edu Command Encapsulate requests for service from an object

More information

Design Patterns and Frameworks Command

Design Patterns and Frameworks Command Design Patterns and Frameworks Command Oliver Haase Oliver Haase Emfra Command 1/13 Description Classification: Object-based behavioral pattern Purpose: Encapsulate a command as an object. Allows to dynamically

More information

Undo/Redo. Principles, concepts, and Java implementation

Undo/Redo. Principles, concepts, and Java implementation Undo/Redo Principles, concepts, and Java implementation Direct Manipulation Principles There is a visible and continuous representation of the domain objects and their actions. Consequently, there is little

More information

2IP15 Programming Methods

2IP15 Programming Methods Lecture 1: Introduction, Functional Decomposition 2IP15 Programming Methods From Small to Large Programs Tom Verhoeff Eindhoven University of Technology Department of Mathematics & Computer Science Software

More information

Comp-304 : Command Lecture 22. Alexandre Denault Original notes by Marc Provost and Hans Vangheluwe Computer Science McGill University Fall 2007

Comp-304 : Command Lecture 22. Alexandre Denault Original notes by Marc Provost and Hans Vangheluwe Computer Science McGill University Fall 2007 Command Comp-304 : Command Lecture 22 Alexandre Denault Original notes by Marc Provost and Hans Vangheluwe Computer Science McGill University Fall 2007 Classic Example Problem User interface toolkit includes

More information

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 5: Will be an open-ended Swing project. "Programming Contest"

More information

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun! Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Why are we studying Swing? 1. Useful & fun! 2. Good application of OOP techniques

More information

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Graphics. Lecture 18 COP 3252 Summer June 6, 2017 Graphics Lecture 18 COP 3252 Summer 2017 June 6, 2017 Graphics classes In the original version of Java, graphics components were in the AWT library (Abstract Windows Toolkit) Was okay for developing simple

More information

Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms.

Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms. Java GUI Windows Events Drawing 1 Java GUI Toolkits Toolkit AWT Description Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms.

More information

UI Software Organization

UI Software Organization UI Software Organization The user interface From previous class: Generally want to think of the UI as only one component of the system Deals with the user Separate from the functional core (AKA, the app

More information

Pattern-Oriented Software Design (Fall 2012) Homework #2 (Due: 10/19/2012)

Pattern-Oriented Software Design (Fall 2012) Homework #2 (Due: 10/19/2012) Pattern-Oriented Software Design (Fall 2012) Homework #2 (Due: 10/19/2012) 1. Introduction In this homework, we will add new features to ADD. Command pattern will be applied to support redo/undo operations.

More information

Design Patterns: Prototype, State, Composite, Memento

Design Patterns: Prototype, State, Composite, Memento Design Patterns: Prototype, State, Composite, Memento Let s start by considering the CanvasEditor as we had it at the end of the last class. Recall that when a button was clicked, the button s custom ActionListener

More information

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class CHAPTER GRAPHICAL USER INTERFACES 10 Slides by Donald W. Smith TechNeTrain.com Final Draft 10/30/11 10.1 Frame Windows Java provides classes to create graphical applications that can run on any major graphical

More information

Graphical User Interface (GUI)

Graphical User Interface (GUI) Graphical User Interface (GUI) An example of Inheritance and Sub-Typing 1 Java GUI Portability Problem Java loves the idea that your code produces the same results on any machine The underlying hardware

More information

Assignment 2. Application Development

Assignment 2. Application Development Application Development Assignment 2 Content Application Development Day 2 Lecture The lecture covers the key language elements of the Java programming language. You are introduced to numerical data and

More information

Lecture 18 Java Graphics and GUIs

Lecture 18 Java Graphics and GUIs CSE 331 Software Design and Implementation The plan Today: introduction to Java graphics and Swing/AWT libraries Then: event-driven programming and user interaction Lecture 18 Java Graphics and GUIs None

More information

User interfaces and Swing

User interfaces and Swing User interfaces and Swing Overview, applets, drawing, action listening, layout managers. APIs: java.awt.*, javax.swing.*, classes names start with a J. Java Lectures 1 2 Applets public class Simple extends

More information

Announcements. Introduction. Lecture 18 Java Graphics and GUIs. Announcements. CSE 331 Software Design and Implementation

Announcements. Introduction. Lecture 18 Java Graphics and GUIs. Announcements. CSE 331 Software Design and Implementation CSE 331 Software Design and Implementation Lecture 18 Java Graphics and GUIs Announcements Leah Perlmutter / Summer 2018 Announcements Quiz 6 due Thursday 8/2 Homework 7 due Thursday 8/2 Regression testing

More information

Graphical User Interface (GUI)

Graphical User Interface (GUI) Graphical User Interface (GUI) An example of Inheritance and Sub-Typing 1 Java GUI Portability Problem Java loves the idea that your code produces the same results on any machine The underlying hardware

More information

Class 16: The Swing Event Model

Class 16: The Swing Event Model Introduction to Computation and Problem Solving Class 16: The Swing Event Model Prof. Steven R. Lerman and Dr. V. Judson Harward 1 The Java Event Model Up until now, we have focused on GUI's to present

More information

The following topics will be covered in this course (not necessarily in this order).

The following topics will be covered in this course (not necessarily in this order). The following topics will be covered in this course (not necessarily in this order). Introduction The course focuses on systematic design of larger object-oriented programs. We will introduce the appropriate

More information

Widgets. Widgets Widget Toolkits. User Interface Widget

Widgets. Widgets Widget Toolkits. User Interface Widget Widgets Widgets Widget Toolkits 2.3 Widgets 1 User Interface Widget Widget is a generic name for parts of an interface that have their own behavior: buttons, drop-down menus, spinners, file dialog boxes,

More information

CSSE 220. Event Based Programming. Check out EventBasedProgramming from SVN

CSSE 220. Event Based Programming. Check out EventBasedProgramming from SVN CSSE 220 Event Based Programming Check out EventBasedProgramming from SVN Interfaces are contracts Interfaces - Review Any class that implements an interface MUST provide an implementation for all methods

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Hal Perkins Winter 2018 Java Graphics and GUIs 1 The plan Today: introduction to Java graphics and Swing/AWT libraries Then: event-driven programming and user interaction

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Hal Perkins Spring 2017 GUI Event-Driven Programming 1 The plan User events and callbacks Event objects Event listeners Registering listeners to handle events Anonymous

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 34 April 18, 2013 Swing II: Layout & Designing a GUI app How is HW10 going so far? 1. not started 2. started reading 3. got an idea for what game to

More information

IT101. Graphical User Interface

IT101. Graphical User Interface IT101 Graphical User Interface Foundation Swing is a platform-independent set of Java classes used for user Graphical User Interface (GUI) programming. Abstract Window Toolkit (AWT) is an older Java GUI

More information

JAVA CONCEPTS Early Objects

JAVA CONCEPTS Early Objects INTERNATIONAL STUDENT VERSION JAVA CONCEPTS Early Objects Seventh Edition CAY HORSTMANN San Jose State University Wiley CONTENTS PREFACE v chapter i INTRODUCTION 1 1.1 Computer Programs 2 1.2 The Anatomy

More information

Lab & Assignment 1. Lecture 3: ArrayList & Standard Java Graphics. Random Number Generator. Read Lab & Assignment Before Lab Wednesday!

Lab & Assignment 1. Lecture 3: ArrayList & Standard Java Graphics. Random Number Generator. Read Lab & Assignment Before Lab Wednesday! Lab & Assignment 1 Lecture 3: ArrayList & Standard Java Graphics CS 62 Fall 2015 Kim Bruce & Michael Bannister Strip with 12 squares & 5 silver dollars placed randomly on the board. Move silver dollars

More information

CIS 120 Programming Languages and Techniques. Final Exam, May 3, 2011

CIS 120 Programming Languages and Techniques. Final Exam, May 3, 2011 CIS 120 Programming Languages and Techniques Final Exam, May 3, 2011 Name: Pennkey: My signature below certifies that I have complied with the University of Pennsylvania s Code of Academic Integrity in

More information

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction CSC 160 LAB 8-1 DIGITAL PICTURE FRAME PROFESSOR GODFREY MUGANDA DEPARTMENT OF COMPUTER SCIENCE 1. Introduction Download and unzip the images folder from the course website. The folder contains 28 images

More information

Advanced Effects in Java Desktop Applications

Advanced Effects in Java Desktop Applications Advanced Effects in Java Desktop Applications Kirill Grouchnikov, Senior Software Engineer, Amdocs kirillcool@yahoo.com http://www.pushing-pixels.org OSCON 2007 Agenda Swing pipeline Hooking into the pipeline

More information

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics Topic 9: Swing Outline Swing = Java's GUI library Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 7: Expand moving shapes from Assignment 4 into game. "Programming

More information

Name: CSC143 Exam 1 1 CSC 143. Exam 1. Write also your name in the appropriate box of the scantron

Name: CSC143 Exam 1 1 CSC 143. Exam 1. Write also your name in the appropriate box of the scantron Name: CSC143 Exam 1 1 CSC 143 Exam 1 Write also your name in the appropriate box of the scantron Name: CSC143 Exam 1 2 Multiple Choice Questions (30 points) Answer all of the following questions. READ

More information

Introduction to GUIs. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2014

Introduction to GUIs. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2014 Introduction to GUIs Principles of Software Construction: Objects, Design, and Concurrency Jonathan Aldrich and Charlie Garrod Fall 2014 Slides copyright 2014 by Jonathan Aldrich, Charlie Garrod, Christian

More information

Design Patterns. it s about the Observer pattern, the Command pattern, MVC, and some GUI. some more

Design Patterns. it s about the Observer pattern, the Command pattern, MVC, and some GUI. some more Lecture: Software Engineering, Winter Semester 2011/2012 some more Design Patterns it s about the Observer pattern, the Command pattern, MVC, and some GUI Design Pattern *...+ describes a problem which

More information

Design Patterns: Composite, Memento, Template Method, Decorator, Chain of Responsibility, Interpreter

Design Patterns: Composite, Memento, Template Method, Decorator, Chain of Responsibility, Interpreter Design Patterns: Composite, Memento, Template Method, Decorator, Chain of Responsibility, Interpreter Composite Outline for Week 14 [Skrien 8.7] We need to allow users to group figures together to make

More information

ming 3 Resize the Size to [700, 500]. Note that the background containers in the program code: reference the then under () { 153, 255, 0 ) );

ming 3 Resize the Size to [700, 500]. Note that the background containers in the program code: reference the then under () { 153, 255, 0 ) ); ECCS 166 Programm ming 3 Dr. Estell Spring Quarter 20111 Laboratory Assignmen nt 7 Graphics and Polymorphism 15 April 2011 1. The purpose of the next few laboratory assignments is to create a simple drawing

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 36 April 18, 2012 Swing IV: Mouse and Keyboard Input Announcements Lab this week is review (BRING QUESTIONS) Game Project is out, due Tuesday April

More information

GUI Event Handlers (Part I)

GUI Event Handlers (Part I) GUI Event Handlers (Part I) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen University 1 Agenda General event

More information

Chapter 6 Introduction to Defining Classes

Chapter 6 Introduction to Defining Classes Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of

More information

G51PRG: Introduction to Programming Second semester Applets and graphics

G51PRG: Introduction to Programming Second semester Applets and graphics G51PRG: Introduction to Programming Second semester Applets and graphics Natasha Alechina School of Computer Science & IT nza@cs.nott.ac.uk Previous two lectures AWT and Swing Creating components and putting

More information

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class.

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class. Q1. If you add a component to the CENTER of a border layout, which directions will the component stretch? A1. The component will stretch both horizontally and vertically. It will occupy the whole space

More information

Software Construction

Software Construction Lecture 5: Robustness, Exceptions Software Construction in Java for HSE Moscow Tom Verhoeff Eindhoven University of Technology Department of Mathematics & Computer Science Software Engineering & Technology

More information

Dartmouth College Computer Science 10, Fall 2015 Midterm Exam

Dartmouth College Computer Science 10, Fall 2015 Midterm Exam Dartmouth College Computer Science 10, Fall 2015 Midterm Exam 6.00-9.00pm, Monday, October 19, 2015 105 Dartmouth Hall Professor Prasad Jayanti Print your name: Print your section leader name: If you need

More information

Widgets. Widgets Widget Toolkits. 2.3 Widgets 1

Widgets. Widgets Widget Toolkits. 2.3 Widgets 1 Widgets Widgets Widget Toolkits 2.3 Widgets 1 User Interface Widget Widget is a generic name for parts of an interface that have their own behavior: buttons, drop-down menus, spinners, file dialog boxes,

More information

Windows and Events. created originally by Brian Bailey

Windows and Events. created originally by Brian Bailey Windows and Events created originally by Brian Bailey Announcements Review next time Midterm next Friday UI Architecture Applications UI Builders and Runtimes Frameworks Toolkits Windowing System Operating

More information

Graphics and Painting

Graphics and Painting Graphics and Painting Lecture 17 CGS 3416 Fall 2015 November 30, 2015 paint() methods Lightweight Swing components that extend class JComponent have a method called paintcomponent, with this prototype:

More information

Framework. Set of cooperating classes/interfaces. Example: Swing package is framework for problem domain of GUI programming

Framework. Set of cooperating classes/interfaces. Example: Swing package is framework for problem domain of GUI programming Frameworks 1 Framework Set of cooperating classes/interfaces Structure essential mechanisms of a problem domain Programmer can extend framework classes, creating new functionality Example: Swing package

More information

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in Lab 4 D0010E Object-Oriented Programming and Design Lecture 9 Lab 4: You will implement a game that can be played over the Internet. The networking part has already been written. Among other things, the

More information

GUI Implementation Support

GUI Implementation Support GUI Implementation Support Learning Objectives: Why GUIs? What is a GUI? Why is implementation support needed? What kinds of implementation support are available? Basic concepts in OO GUI toolkit & app

More information

You must include this cover sheet. Either type up the assignment using theory4.tex, or print out this PDF.

You must include this cover sheet. Either type up the assignment using theory4.tex, or print out this PDF. 15-122 Assignment 4 Page 1 of 12 15-122 : Principles of Imperative Computation Fall 2012 Assignment 4 (Theory Part) Due: Thursday, October 18, 2012 at the beginning of lecture Name: Andrew ID: Recitation:

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 35 April 15, 2013 Swing III: OO Design, Mouse InteracGon Announcements HW10: Game Project is out, due Tuesday, April 23 rd at midnight If you want

More information

Lecture 19 GUI Events

Lecture 19 GUI Events CSE 331 Software Design and Implementation Lecture 19 GUI Events The plan User events and callbacks Event objects Event listeners Registering listeners to handle events Anonymous inner classes Proper interaction

More information

PA3 Design Specification

PA3 Design Specification PA3 Teaching Data Structure 1. System Description The Data Structure Web application is written in JavaScript and HTML5. It has been divided into 9 pages: Singly linked page, Stack page, Postfix expression

More information

THOMAS LATOZA SWE 621 FALL 2018 DESIGN PATTERNS

THOMAS LATOZA SWE 621 FALL 2018 DESIGN PATTERNS THOMAS LATOZA SWE 621 FALL 2018 DESIGN PATTERNS LOGISTICS HW3 due today HW4 due in two weeks 2 IN CLASS EXERCISE What's a software design problem you've solved from an idea you learned from someone else?

More information

TDDB84: Lecture 6. Adapter, Bridge, Observer, Chain of Responsibility, Memento, Command. fredag 4 oktober 13

TDDB84: Lecture 6. Adapter, Bridge, Observer, Chain of Responsibility, Memento, Command. fredag 4 oktober 13 TDDB84: Lecture 6 Adapter, Bridge, Observer, Chain of Responsibility, Memento, Command Creational Abstract Factory Singleton Builder Structural Composite Proxy Bridge Adapter Template method Behavioral

More information

Jonathan Aldrich Charlie Garrod

Jonathan Aldrich Charlie Garrod Principles of Software Construction: Objects, Design, and Concurrency (Part 3: Design Case Studies) Introduction to GUIs Jonathan Aldrich Charlie Garrod School of Computer Science 1 Administrivia Homework

More information

Functions BCA-105. Few Facts About Functions:

Functions BCA-105. Few Facts About Functions: Functions When programs become too large and complex and as a result the task of debugging, testing, and maintaining becomes difficult then C provides a most striking feature known as user defined function

More information

H212 Introduction to Software Systems Honors

H212 Introduction to Software Systems Honors Introduction to Software Systems Honors Lecture #19: November 4, 2015 1/14 Third Exam The third, Checkpoint Exam, will be on: Wednesday, November 11, 2:30 to 3:45 pm You will have 3 questions, out of 9,

More information

CSE 331 Software Design and Implementation. Lecture 19 GUI Events

CSE 331 Software Design and Implementation. Lecture 19 GUI Events CSE 331 Software Design and Implementation Lecture 19 GUI Events Leah Perlmutter / Summer 2018 Announcements Announcements Quiz 7 due Thursday 8/9 Homework 8 due Thursday 8/9 HW8 has a regression testing

More information

CS 251 Intermediate Programming GUIs: Components and Layout

CS 251 Intermediate Programming GUIs: Components and Layout CS 251 Intermediate Programming GUIs: Components and Layout Brooke Chenoweth University of New Mexico Fall 2017 import javax. swing.*; Hello GUI public class HelloGUI extends JFrame { public HelloGUI ()

More information

: Principles of Imperative Computation. Fall Assignment 5: Interfaces, Backtracking Search, Hash Tables

: Principles of Imperative Computation. Fall Assignment 5: Interfaces, Backtracking Search, Hash Tables 15-122 Assignment 3 Page 1 of 12 15-122 : Principles of Imperative Computation Fall 2012 Assignment 5: Interfaces, Backtracking Search, Hash Tables (Programming Part) Due: Monday, October 29, 2012 by 23:59

More information

1.00/1.001 Introduction to Computers and Engineering Problem Solving Spring Quiz 2

1.00/1.001 Introduction to Computers and Engineering Problem Solving Spring Quiz 2 1.00/1.001 Introduction to Computers and Engineering Problem Solving Spring 2010 - Quiz 2 Name: MIT Email: TA: Section: You have 80 minutes to complete this exam. For coding questions, you do not need

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 35 April 21, 2014 Swing III: Paint demo, Mouse InteracFon HW 10 has a HARD deadline Announcements You must submit by midnight, April 30 th Demo your

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 33 April 16, 2014 Swing I: Drawing and Event Handling Set set = new TreeSet (); Map map = new TreeMap

More information

Computer Science 62. Bruce/Mawhorter Fall 16. Midterm Examination. October 5, Question Points Score TOTAL 52 SOLUTIONS. Your name (Please print)

Computer Science 62. Bruce/Mawhorter Fall 16. Midterm Examination. October 5, Question Points Score TOTAL 52 SOLUTIONS. Your name (Please print) Computer Science 62 Bruce/Mawhorter Fall 16 Midterm Examination October 5, 2016 Question Points Score 1 15 2 10 3 10 4 8 5 9 TOTAL 52 SOLUTIONS Your name (Please print) 1. Suppose you are given a singly-linked

More information

Topics. Java arrays. Definition. Data Structures and Information Systems Part 1: Data Structures. Lecture 3: Arrays (1)

Topics. Java arrays. Definition. Data Structures and Information Systems Part 1: Data Structures. Lecture 3: Arrays (1) Topics Data Structures and Information Systems Part 1: Data Structures Michele Zito Lecture 3: Arrays (1) Data structure definition: arrays. Java arrays creation access Primitive types and reference types

More information

Computer Science 210: Data Structures. Intro to Java Graphics

Computer Science 210: Data Structures. Intro to Java Graphics Computer Science 210: Data Structures Intro to Java Graphics Summary Today GUIs in Java using Swing in-class: a Scribbler program READING: browse Java online Docs, Swing tutorials GUIs in Java Java comes

More information

Lecture 6. Design (3) CENG 412-Human Factors in Engineering May

Lecture 6. Design (3) CENG 412-Human Factors in Engineering May Lecture 6. Design (3) CENG 412-Human Factors in Engineering May 28 2009 1 Outline Prototyping techniques: - Paper prototype - Computer prototype - Wizard of Oz Reading: Wickens pp. 50-57 Marc Rettig: Prototyping

More information

1.00/ Introduction to Computers and Engineering Problem Solving. Quiz 2 / November 10, 2005

1.00/ Introduction to Computers and Engineering Problem Solving. Quiz 2 / November 10, 2005 1.00/1.001 Introduction to Computers and Engineering Problem Solving Quiz 2 / November 10, 2005 Name: Email Address: TA: Section: You have 90 minutes to complete this exam. For coding questions, you do

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 34 April 13, 2017 Model / View / Controller Chapter 31 How is the Game Project going so far? 1. not started 2. got an idea 3. submitted design proposal

More information

+! Today. Lecture 3: ArrayList & Standard Java Graphics 1/26/14! n Reading. n Objectives. n Reminders. n Standard Java Graphics (on course webpage)

+! Today. Lecture 3: ArrayList & Standard Java Graphics 1/26/14! n Reading. n Objectives. n Reminders. n Standard Java Graphics (on course webpage) +! Lecture 3: ArrayList & Standard Java Graphics +! Today n Reading n Standard Java Graphics (on course webpage) n Objectives n Review for this week s lab and homework assignment n Miscellanea (Random,

More information

Graphic Interface Programming II Events and Threads. Uppsala universitet

Graphic Interface Programming II Events and Threads. Uppsala universitet Graphic Interface Programming II Events and Threads IT Uppsala universitet Animation Animation adds to user experience Done right, it enhances the User Interface Done wrong, it distracts and irritates

More information

APCS-AB: Java. Recursion in Java December 12, week14 1

APCS-AB: Java. Recursion in Java December 12, week14 1 APCS-AB: Java Recursion in Java December 12, 2005 week14 1 Check point Double Linked List - extra project grade Must turn in today MBCS - Chapter 1 Installation Exercises Analysis Questions week14 2 Scheme

More information

Lecture 9. Lecture

Lecture 9. Lecture Layout Components MVC Design PaCern GUI Programming Observer Design PaCern D0010E Lecture 8 - Håkan Jonsson 1 Lecture 8 - Håkan Jonsson 2 Lecture 8 - Håkan Jonsson 3 1 1. GUI programming In the beginning,

More information

Here are the steps to get the files for this project after logging in on acad/bill.

Here are the steps to get the files for this project after logging in on acad/bill. CSC 243, Java Programming, Spring 2013, Dr. Dale Parson Assignment 5, handling events in a working GUI ASSIGNMENT due by 11:59 PM on Thursday May 9 via gmake turnitin Here are the steps to get the files

More information

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. QUEEN'S UNIVERSITY SCHOOL OF COMPUTING HAND IN Answers Are Recorded on Question Paper CISC124, WINTER TERM, 2012 FINAL EXAMINATION 9am to 12pm, 26 APRIL 2012 Instructor: Alan McLeod If the instructor is

More information

Exam Review. CSE 331 Section 10 12/6/12. Slides by Kellen Donohue with material from Mike Ernst

Exam Review. CSE 331 Section 10 12/6/12. Slides by Kellen Donohue with material from Mike Ernst Exam Review CSE 331 Section 10 12/6/12 Slides by Kellen Donohue with material from Mike Ernst Course Logistics All homework s done (except late days) HW8 returned HW7 being graded HW9 will be graded during

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 17 Feb 28 th, 2014 Objects and GUI Design Where we re going HW 6: Build a GUI library and client applicaton from scratch in OCaml Available soon Due

More information

WIMP Elements. GUI goo. What is WIMP?

WIMP Elements. GUI goo. What is WIMP? WIMP Elements GUI goo What is WIMP? 1 There are many kinds of WIMPs WIMP The GUI Interface Windows Icons Menus Pointers 2 Windows Icons Pointers Menus Windows Windows are areas of the screen that act like

More information

Anagrams Architectural Design Document

Anagrams Architectural Design Document 1 2 3 Anagrams Architectural Design Document Irritable Enterprises, Inc. 13 June 2008 Version 0.3 For Review 5 pages 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 1 Introduction

More information

Layout. Dynamic layout, Swing and general layout strategies

Layout. Dynamic layout, Swing and general layout strategies Layout Dynamic layout, Swing and general layout strategies Two Interface Layout Tasks Designing a spatial layout of widgets in a container Adjusting that spatial layout when container is resized Both

More information