Programming Languages and Techniques (CIS120)

Similar documents
Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120)

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120)

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120)

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

ECE 462 Object-Oriented Programming using C++ and Java. Key Inputs in Java Games

Method Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is

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

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

HW#1: Pencil Me In Status!? How was Homework #1? Reminder: Handouts. Homework #2: Java Draw Demo. 3 Handout for today! Lecture-Homework mapping.

Programming Languages and Techniques (CIS120)

Computer Science 210: Data Structures. Intro to Java Graphics

Graphical User Interfaces 2

GUI in Java TalentHome Solutions

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2,

Lecture 5: Java Graphics

Programming Languages and Techniques (CIS120)

Handling Mouse and Keyboard Events

Graphical User Interfaces 2

Programming Languages and Techniques (CIS120)

The AWT Event Model 9

Final Exam. Name: Student ID Number: Signature:

Java for Interfaces and Networks (DT3010, HT10)

Component-Based Behavioural Modelling with High-Level Petri Nets

Graphical User Interfaces 2

Chapter 1 GUI Applications

Programming Languages and Techniques (CIS120)

Unit 7: Event driven programming

Outline. More on the Swing API Graphics: double buffering and timers Model - View - Controller paradigm Applets

CSE 331 Software Design & Implementation

Lecture 3: Java Graphics & Events

GUI Event Handlers (Part I)

PESIT Bangalore South Campus

Event Binding. Different Approaches Global Hooks. 2.5 Event Binding 1

Assignment 2 Team Project: Distributed System and Application

Design Patterns: Prototype, State, Composite, Memento

Lecture 19 GUI Events

CS 2113 Software Engineering

User interfaces and Swing

CIS 120 Final Exam 16 December Name (printed): Pennkey (login id):

CS11 Java. Fall Lecture 4

Chapter 10. Further Abstraction Techniques

Parallel and Distributed Algorithms. Moore s law and processors. University of Massachuse;s Amherst ECE 242 Data Structures and Algorithms Lecture 33

CSE 331 Software Design and Implementation. Lecture 19 GUI Events

CS 180 Problem Solving and Object Oriented Programming Fall 2011

Class Hierarchy and Interfaces. David Greenstein Monta Vista High School

Exam: Applet, Graphics, Events: Mouse, Key, and Focus

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

CSE wi Final Exam 3/12/18. Name UW ID#

CS 180 Problem Solving and Object Oriented Programming Fall 2011

UCLA PIC 20A Java Programming

CIT 590 Homework 10 Battleship

BASICS OF GRAPHICAL APPS

Programming Languages and Techniques (CIS120e)

Cheng, CSE870. More Frameworks. Overview. Recap on OOP. Acknowledgements:

Programming Languages 2nd edition Tucker and Noonan"

Lecture 5. Lecture

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

3 ADT Implementation in Java

L4,5: Java Overview II

Chapter 14: Applets and More

8/23/2014. Chapter Topics. Introduction to Applets. Introduction to Applets. Introduction to Applets. Applet Limitations. Chapter 14: Applets and More

Programming Languages and Techniques (CIS120)

Our second exam is Thursday, November 10. Note that it will not be possible to get all the homework submissions graded before the exam.

Widgets. Overview. Widget. Widgets Widget toolkits Lightweight vs. heavyweight widgets Swing Widget Demo

class BankFilter implements Filter { public boolean accept(object x) { BankAccount ba = (BankAccount) x; return ba.getbalance() > 1000; } }

Widget. Widget is a generic name for parts of an interface that have their own behaviour. e.g., buttons, progress bars, sliders, drop-down

UI Software Organization

(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI

MARS AREA SCHOOL DISTRICT Curriculum TECHNOLOGY EDUCATION

Come & Join Us at VUSTUDENTS.net

CIS 120 Midterm II November 16, 2012 SOLUTIONS

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

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

Systems Programming Graphical User Interfaces

Chapter 14: Applets and More

CSIS 10A Practice Final Exam Solutions

I/O Framework and Case Study. CS151 Chris Pollett Nov. 2, 2005.

CS 251 Intermediate Programming GUIs: Components and Layout

CS11 Java. Fall Lecture 3

BM214E Object Oriented Programming Lecture 13

Swing Rocks - A Tribute to Filthy Rich Clients

To gain experience using GUI components and listeners.

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

CS 111: Programming Fundamentals II

CS50 Quiz Review. November 13, 2017

Programming Mobile Devices J2SE GUI

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners

Our second exam is Monday, April 3. Note that it will not be possible to get all the homework submissions graded before the exam.

Advanced Java Programming (17625) Event Handling. 20 Marks

UML and OOD. Some terms related to OOD. Dependency. Coupling. Interfaces. Multiple Interfaces

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline

Transcription:

Programming Languages and Techniques (CIS120) Lecture 35 November 30 th 2015 Design PaBerns Model / View / Controller Chapter 31

Game project grading Game Design Proposal Milestone Due: (12 points) Tuesday December 1 st at 11:59pm (Should take about 1 hour) Final Program Due: Tuesday December 8 th at 11:59pm (88 points) Submit zipfile online, submission only checks if your code compiles Grade based on demo with your TA during reading days Make sure that you test your program in Moore 100, especially if you use outside libraries Grading rubric on the assignment website RecommendaWon: don t be too ambiwous. NO LATE SUBMISSIONS PERMITTED

How is the Game Project going so far? 1. not started 2. got an idea 3. submibed design proposal 4. started coding 5. it's somewhat working 6. it's mostly working 7. debugging / polishing 8. done!

Course Trajectory Today: Thinking about soaware design at a larger scale (Much more than we can cover) Java loose ends Hashing and hashcode Touching on Java advanced concepts Garbage collecwon Concurrency CIS120 / Spring 2012

Design PaBerns Design PaBerns InfluenWal OO design book published in 1994 IdenWfies many common situawons and "paberns" for implemenwng them in OO languages Some we have seen explicitly: e.g. Iterator pabern Some we've used but not explicitly described: e.g. The Broadcast class from the Chat HW uses the Factory pabern Some are workarounds for OO's lack of some features: e.g. The Visitor pabern is like OCaml's fold + pabern matching CIS120 / Spring 2012

GUI Design PaBerns Model/View/Controller Adapters CIS120 / Spring 2012

Example 1: Java Paint

Paint Program Structure Main frame for applicawon (class Paint) List of shapes to draw The current color The current line thickness Drawing panel (class Canvas, inner class of Paint) Model View Control panel (class JPanel Contains radio bubons for selecwng shape to draw Line thickness checkbox, undo and quit bubons Controller ConnecWons between Preview shape (if any ) Preview Shape: View <- > Controller MouseAdapter: Controller <- > Model

Example 2: CheckBox true or false Views Selected? Pressed? Model setselected mouselistener keylistener Controllers Class JToggleButton.ToggleButtonModel boolean isselected() Checks if the bubon is selected. void setpressed(boolean b) Sets the pressed state of the bubon. void setselected(boolean b) Sets the selected state of the bubon. CIS120 / Spring 2012

Example 3: Chat Server getchannels getusers getowner Views Internal RepresentaWon owners: Map<Channel, Users> users: Map<Channel, Set<Users>> Model createchannel joinchannel invite kick Controllers ServerModel CIS120 / Spring 2012

Example 4: Web Pages Internal RepresentaWon: DOM (Document Object Model) Model JavaScript API document. addeventlistener() Controllers CIS120 / Spring 2012 Views

MVC PaBern Updates Manipulates Model Adjusts View(s) Controller Sees Uses CIS120 / Spring 2012 User

MVC Benefits? Decouples important "model state" from how that state is presented and manipulated Suggests where to insert interfaces in the design Makes the model testable independent of the GUI MulWple views e.g. from two different angles, or for mulwple different users MulWple controllers e.g. mouse vs. keyboard interacwon CIS120 / Spring 2012

MVC VariaWons Many variawons on MVC pabern Hierarchical / Nested As in the Swing libraries, in which JComponents oaen have a "model" and a "controller" part Coupling between Model / View or View / Controller e.g. in Paint the Model and the View are quite coupled because the model caries most of the informawon about the view CIS120 / Spring 2012

Adapters MouseAdapter KeyBoardAdapter

Mouse InteracWon in Paint Point Mode Mouse Click (in the canvas) [add new point] Line BuBon press Point BuBon press Mouse Press [store point, set preview shape] Mouse Drag [update preview] LineStart Mode LineEnd Mode CIS120 Mouse Release [add new line, set preview to null]

Two interfaces for mouse listeners interface MouseListener extends EventListener { public void mouseclicked(mouseevent e); public void mouseentered(mouseevent e); public void mouseexited(mouseevent e); public void mousepressed(mouseevent e); public void mousereleased(mouseevent e); } interface MouseMotionListener extends EventListener { public void mousedragged(mouseevent e); } public void mousemoved(mouseevent e); CIS120

Lots of boilerplate There are seven methods in the two interfaces. We only want to do something intereswng for three of them. Need "trivial" implementawons of the other four to implement the interface public void mousemoved(mouseevent e) { return; } public void mouseclicked(mouseevent e) { return; } public void mouseentered(mouseevent e) { return; } public void mouseexited(mouseevent e) { return; } SoluWon: MouseAdapter class CIS120

Adapter classes: Swing provides a collecwon of abstract event adapter classes These adapter classes implement listener interfaces with empty, do- nothing methods To implement a listener class, we extend an adapter class and override just the methods we need private class Mouse extends MouseAdapter { public void mousepressed(mouseevent e) { } public void mousereleased(mouseevent e) { } public void mousedragged(mouseevent e) { } } CIS120