Programming Languages and Techniques (CIS120)

Similar documents
Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120)

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

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

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

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

Programming Languages and Techniques (CIS120)

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

Programming Languages and Techniques (CIS120)

Object-oriented programming in Java (2)

Graphical User Interfaces 2

Programming Languages and Techniques (CIS120)

H212 Introduction to Software Systems Honors

Java Foundations John Lewis Peter DePasquale Joe Chase Third Edition

Graphical User Interfaces 2

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120)

Graphical User Interfaces 2

CS211 GUI Dynamics. Announcements. Motivation/Overview. Example Revisted

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120)

CS 134 Test Program #2

Object Orientated Programming in Java. Benjamin Kenwright

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

IT101. Graphical User Interface

Abstract Classes and Interfaces

G51PRG: Introduction to Programming Second semester Applets and graphics

Charlie Garrod Michael Hilton

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

Name: Pennkey (eg, sweirich): CIS 120 Final Exam May 8, 2012

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

CSE1720 Lecture 08; Week 05 Lecture 09 Second level Third level Fourth level Fifth level

The init() Method. Browser Calling Applet Methods

TYPES OF INTERACTORS Prasun Dewan Department of Computer Science University of North Carolina at Chapel Hill

Lecture 9. Lecture

Programming Languages and Techniques (CIS120)

Software Construction

Announcements. Java Graphics. Exceptions. Java Odds & Ends

Programming Languages and Techniques (CIS120)

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.

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

UI Toolkits. HCID 520 User Interface Software & Technology

+! 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: Java Graphics & Events

CIS 120 Final Exam May 7, Name (printed): Pennkey (login id):

CSE1720. Objectives for this class meeting 2/10/2014. Cover 2D Graphics topic: displaying images. Timer class, a basic ActionListener

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

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

Lecture 5: Java Graphics

CS11 Java. Fall Lecture 4

Graphical User Interface (GUI)

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

Graphical User Interface (GUI)

User interfaces and Swing

Programming Languages and Techniques (CIS120)

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

Lecture 5. Lecture

Come & Join Us at VUSTUDENTS.net

Name: Pennkey: CIS 120 Midterm II November 18, 2011

CS 180 Problem Solving and Object Oriented Programming Fall 2011

CS 170 Java Programming 1. Week 15: Interfaces and Exceptions

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

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

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

Programming Languages and Techniques (CIS120)

Class 16: The Swing Event Model

Java Programming Lecture 6

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

Programming Languages and Techniques (CIS120)

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

Programming Languages and Techniques (CIS120)

Inheritance and Interfaces

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

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!

CS 134 Programming Exercise 7:

Introduction to concurrency and GUIs

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Programming Languages and Techniques (CIS120e)

Agenda. Programming Seminar. By: dr. Amal Khalifa. Coordinate systems Colors Fonts Drawing shapes Graphics2D API

GUI Event Handlers (Part I)

CPS221 Lecture: Threads

Graphical User Interfaces (GUIs)

Programming Languages and Techniques (CIS120)

Charlie Garrod Michael Hilton

Interlude. Object Oriented Design

CSE 331 Software Design & Implementation

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

Windows and Events. created originally by Brian Bailey

Programming Languages and Techniques (CIS120)

Charlie Garrod Bogdan Vasilescu

CSCI 201L Midterm Written SOLUTION Summer % of course grade

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Maintain binary search tree property nodes to the left are less than the current node, nodes to the right are greater

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

Transcription:

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 24 th If you want to do a game other than one of the ones listed, send email to tas120@seas.upenn.edu Final Exam Date: Tuesday, May 8 th Time: 9:00 AM- 11:00 AM Place: SKIR AUD Review session: TBA during finals

Paint Mouse and Keyboard interac_on

Basic structure Main frame for applica_on (class Paint) the MODEL Drawing panel (class Canvas, inner class of Paint) the VIEW Control panel (class JPanel) Contains radio buaons for interac_ng with the program (part of) the CONTROL Paint class contains the state of the program List of shapes to draw The current color (will always be BLACK today) References to UI components: canvas, modetoolbar How can users update that state?

Keyboard Interac_on

Keyboard Interac_on How to make the program responsive to keyboard input? Concept: keyboard focus A Focusable UI Component is one that can respond to keyboard input Java method requestfocusinwindow gives the focus to a par_cular component Registered KeyListeners for the component react when it is in focus KeyListener Interface void keypressed(keyevent e) Invoked when a key has been pressed void keyreleased(keyevent e) Invoked when a key has been released void keytyped(keyevent e) Invoked when a key has been typed Use KeyAdapter to easily make an instance of this interface

Paint: Comparison with OCaml How does our treatment of shape drawing in Java compare with the OCaml GUI project?

Java Design Summary 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 : actions) s.draw((graphics2d)gc); if (preview!= null) preview.draw((graphics2d)gc); } } Canvas uses dynamic dispatch to draw the shapes

type point = int * int! type shape =! Point of Gctx.color * int * point! Line of Gctx.color * int * point * point! (* Repaint function for displaying the canvas. *)! let repaint (g:gctx.t) : unit =! let actions = List.rev paint.shapes in! let drawit d =! begin match d with! Point (c,t,p) ->!! Gctx.draw_points (set_params g c t) p! Line (c,t,p1,p2) ->! Gctx.draw_line (set_params g c t) p1 p2! end in! List.iter drawit actions! CIS 120

Comparison with OCaml How does our treatment of shape drawing in the Java Paint example compare with the OCaml GUI project? Java: Interface Shape for drawable objects Classes implement that interface Canvas uses dynamic dispatch to draw the shapes Add more shapes by adding more implementa_ons of "Shape" OCaml Datatype specifies variants of drawable objects Canvas uses paaern matching to draw the shapes Add more shapes by adding more variants, and modifying drawit

Datatypes vs. Objects Datatypes Focus on how the data is stored Easy to add new opera_ons Hard to add new variants Objects Focus on what to do with the data Easy to add new variants Hard to add new opera_ons Best for: situa_ons where the structure of the data is fixed (i.e. BSTs) Best for: situa_ons where the interface with the data is fixed (i.e. Shapes) CIS 120

What about Modes? Is Enum the best way to represent them?