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)

Programming Languages and Techniques (CIS120)

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

Programming Languages and Techniques (CIS120)

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

Programming Languages and Techniques (CIS120)

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

Computer Science 210: Data Structures. Intro to Java Graphics

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

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

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

Programming Languages and Techniques (CIS120)

Graphical User Interfaces 2

Graphical User Interfaces 2

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

Graphical User Interfaces 2

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

Programming Languages and Techniques (CIS120)

User interfaces and Swing

Programming Languages and Techniques (CIS120)

Java for Interfaces and Networks (DT3010, HT10)

GUI in Java TalentHome Solutions

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

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)

Component-Based Behavioural Modelling with High-Level Petri Nets

Unit 7: Event driven programming

G51PRG: Introduction to Programming Second semester Applets and graphics

Chapter 14: Applets and More

Handling Mouse and Keyboard Events

Object Orientated Programming in Java. Benjamin Kenwright

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

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

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

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

Programming Languages and Techniques (CIS120)

Java Programming. Computer Science 112

CS 180 Problem Solving and Object Oriented Programming Fall 2011

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

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

Design Patterns: Prototype, State, Composite, Memento

Windows and Events. created originally by Brian Bailey

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

Programming Languages and Techniques (CIS120)

CS 180 Problem Solving and Object Oriented Programming Fall 2011

CS 2113 Software Engineering

L4,5: Java Overview II

The AWT Event Model 9

PESIT Bangalore South Campus

CompSci 125 Lecture 17. GUI: Graphics, Check Boxes, Radio Buttons

Lecture 5: Java Graphics

2IS45 Programming

UCLA PIC 20A Java Programming

Programming Mobile Devices J2SE GUI

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

CS 251 Intermediate Programming GUIs: Components and Layout

(Incomplete) History of GUIs

COSC 123 Computer Creativity. Graphics and Events. Dr. Ramon Lawrence University of British Columbia Okanagan

Swing Rocks - A Tribute to Filthy Rich Clients

Human-Computer Interaction IS4300

Java Programming Lecture 6

CSE115 Lab 4 Fall 2016

CS 106A, Lecture 14 Events and Instance Variables

BASICS OF GRAPHICAL APPS

AP Computer Science Unit 13. Still More Graphics and Animation.

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

CSE 331 Software Design & Implementation

Advanced Java Programming

javax.swing Swing Timer

SAMPLE EXAM Exam 2 Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 5 November 2009

Final Exam. Name: Student ID Number: Signature:

H212 Introduction to Software Systems Honors

CS2110. GUIS: Listening to Events Also anonymous classes versus Java 8 functions. Anonymous functions. Anonymous functions. Anonymous functions

Lecture 3: Java Graphics & Events

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

CSE 331 Software Design and Implementation. Lecture 19 GUI Events

UI Software Organization

Programming Languages and Techniques (CIS120)

CS 349 / SE 382 Design Patterns. Professor Michael Terry January 21, 2009

Programming Languages and Techniques (CIS120)

H212 Introduction to Software Systems Honors

CSE 331 Software Design & Implementation

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.

FirstSwingFrame.java Page 1 of 1

Software Construction

CS 201 Advanced Object-Oriented Programming Lab 10 - Recursion Due: April 21/22, 11:30 PM

Appendix G Navigation and Collision Detection for Web-Based 3D Experiment

Assignment 2. Application Development

CS371m - Mobile Computing. Gestures

CSIS 10A Practice Final Exam Solutions

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

Bean Communication. COMP434B Software Design. Bean Communication. Bean Communication. Bean Communication. Bean Communication

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

Chapter 1 GUI Applications

CS 106A, Lecture 14 Events and Instance Variables

Transcription:

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 project to your TA during reading days TAs have advice for your game source control tutorial collisions difficulty guide Friday s lecture is a BONUS lecture Not directly related to game project or Java libraries No clicker quizzes Fun! CIS120

Java Paint

Basic structure Main class for the applicafon (the MODEL) Drawing area, i.e. Canvas (the VIEW) Control panel (the CONTROLLER) Model stores the state of the applicafon CollecFon of shapes to draw Preview shape (if any ) The current color (will always be BLACK today) The current line thickness View displays the state overrides paintcomponent method and draws each shape in the list Controller updates the state Radio bu`ons for selecfng shape to draw Line thickness checkbox, undo and quit bu`ons

The Model

Dynamic Dispatch for Drawing public interface Shape { } public void draw(graphics gc); Interface describes what shapes can do public class PointShape implements Shape { } public class LineShape implements Shape { } Classes describe how to draw themselves private class Canvas extends JPanel { public void paintcomponent(graphics gc) { super.paintcomponent(gc); for (Shape s : shapes) s.draw(gc); if (preview!= null) preview.draw(gc); } } Canvas uses dynamic dispatch to draw the shapes 6

public class Paint { /** Preview shape for drag and drop */ private Shape preview = null; /** Current drawing color */ private Color color = Color.BLACK; /** Current drawing thickness */ private Stroke stroke = thickstroke; /** Stroke for drawing shapes with thin lines */ public final static Stroke thinstroke = new BasicStroke(1); /** Stroke for drawing shapes with thick lines */ public final static Stroke thickstroke = new BasicStroke(3); /** The shapes that will be drawn on the canvas. */ private??? shapes = new????(); What CollecFon class should we use to store the shapes? 1. TreeSet<Shape> 2. TreeMap<Shape> 3. LinkedList<Shape> 4. Iterable<Shape> 5. None of the above CIS120

The Controller updates the state of the model

Canvas (canvas) JPanel (modetoolbar) JRadioBu`on (point,line) JCheckbox (thick) JBu`on (quit)

Demo: Controller Layout Paint.java

Mouse InteracFon How do we specify what shapes to draw on the canvas? public enum Mode { PointMode, LineStartMode, LineEndMode } private Mode mode = Mode.PointMode;

InteracFon Point Mode Mouse Click (in the canvas) [add new point] Line Bu`on press Point Bu`on press LineStart Mode Mouse Release [add new line, set preview to null] Mouse Drag [update preview] LineEnd Mode CIS120 Mouse Press [store point, set preview]

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 interesfng for three of them. Need "trivial" implementafons 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; } SoluFon: MouseAdapter class CIS120

Adapter classes: Swing provides a collecfon 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