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

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

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

User interfaces and Swing

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

2IS45 Programming

Programming Languages and Techniques (CIS120)

CS 2113 Software Engineering

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

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

Unit 7: Event driven programming

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

Chapter 1 GUI Applications

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

Lecture 19 GUI Events

CSE 331 Software Design & Implementation

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

Programming Languages and Techniques (CIS120)

Graphical User Interfaces 2

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

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120)

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

CSE 331 Software Design and Implementation. Lecture 19 GUI Events

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

UI Software Organization

Course: CMPT 101/104 E.100 Thursday, November 23, 2000

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

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

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

Design patterns for graphical user interface applications

CSSE 220 Day 15. Inheritance. Check out DiscountSubclasses from SVN

User Interface Programming OOP/Java Primer. Step 4 Some Final Checkups

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

Object-Oriented Concepts and Design Principles

Programming Languages and Techniques (CIS120)

DM503 Programming B. Peter Schneider-Kamp.

Programming Languages and Techniques (CIS120)

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

Dartmouth College Computer Science 10, Fall 2015 Midterm Exam

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

Every language has its own scoping rules. For example, what is the scope of variable j in this Java program?

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

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

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.

Programming Languages and Techniques (CIS120)

CSSE 220. Interfaces and Polymorphism. Check out Interfaces from SVN

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

CS11 Java. Fall Lecture 3

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

Starting Out with Java: From Control Structures Through Objects Sixth Edition

BM214E Object Oriented Programming Lecture 13

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

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

G51PRG: Introduction to Programming Second semester Applets and graphics

Programming Languages and Techniques (CIS120)

Strategy Pattern. What is it?

Graphical User Interfaces 2

GUI in Java TalentHome Solutions

CSE 331 Software Design & Implementation

CS2110. GUIS: Listening to Events

Graphical User Interfaces 2

PESIT Bangalore South Campus

Come & Join Us at VUSTUDENTS.net

Programming Languages and Techniques (CIS120)

COMP 102: Test 2 Model Solutions

Computer Science 210: Data Structures. Intro to Java Graphics

CSCI 201L Midterm Programming. Fall % of course grade

Java for Interfaces and Networks (DT3010, HT10)

(Incomplete) History of GUIs

Jonathan Aldrich Charlie Garrod

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

G51PGP Programming Paradigms. Lecture 009 Concurrency, exceptions

The AWT Event Model 9

CSIS 10A Practice Final Exam Solutions

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

UCLA PIC 20A Java Programming

Advanced Java Programming

GUI 4.1 GUI GUI MouseTest.java import javax.swing.*; import java.awt.*; import java.awt.event.*; /* 1 */

Packages Inner Classes

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

encompass a group of features for building Graphical User Interfaces (GUI).

Swing: Building GUIs in Java

Parts of a Contract. Contract Example. Interface as a Contract. Wednesday, January 30, 13. Postcondition. Preconditions.

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

Java Programming Lecture 6

Class 16: The Swing Event Model

Design Patterns: Prototype, State, Composite, Memento

Swing: Building GUIs in Java

Java for Non Majors. Final Study Guide. April 26, You will have an opportunity to earn 20 extra credit points.

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

CS11 Java. Fall Lecture 4

Handling Mouse and Keyboard Events

Queen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb

COMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) )

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components

Component-Based Behavioural Modelling with High-Level Petri Nets

Binghamton University. CS-140 Fall Functional Java

What about Object-Oriented Languages?

Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics

Transcription:

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 defined in the interface. Interfaces represent the abstract idea (and what it can do): Discount (calculate discount) Function (get name, evaluate result) Classes represent the concrete idea: Fixed Discount, Percentage Discount Add, Multiple, Divide, Subtract, etc.

Interfaces Review (continued) The specific method to use at runtime is decided by late-binding Function add = new Add(); double result = add.evaluate(doubles); The declared type of add is Function The instantiation type is Add At run-time, Java will use the method implementation of evaluate from the Add class thanks to late-binding.

Finish the sentence Using interfaces can help reduce between classes. a. Coupling b. Cohesion c. Encapsulation d. Polymorphism We need interfaces for event-based programming in Java.

Graphical User Interfaces in Java We say what to draw Java windowing library: Draws it Gets user input Calls back to us with events We handle events Gooey Hmm, donuts

Events What, When, Why, How? What: Indication that something has occurred in the application When: Click, Key Pressed, Window Closed, etc. Operations that are not required to occur in a specific order User Interaction with screen elements Mouse pressed, mouse released, mouse moved, mouse clicked, button clicked, key pressed, menu item selected,

Events What, When, Why, How? Why: Handles operations that occur in many different orders How: Implement the interface corresponding with the event Ex, public class ButtonListener implements ActionListener {} Create a listener object AND Register the event with event source who will call it Ex, button.addactionlistener(new ButtonListener());

Inner Classes What, When, Why, What: How? Classes defined inside other classes or methods When: Smallish helper classes Often used for ActionListeners Sometimes used for allowing multiple types for an item: Example: Ellipse2D.Double Outer class Inner class

Inner Classes What, When, Why, How? Why: Inner class gets access to the final and static fields and methods of the containing class How: public class OuterClass { //fields and methods } class InnerClass { //inner class s fields and methods }

Anonymous Classes What, When, Why, How? What: Anonymous no name A special case of inner classes When: When you only need one instance The implementation is very small Used for the simplest ActionListeners Why: Provide the scope necessary for implementing the handler How: button.addactionlistener(new ActionListener() { //implement methods }

Inner Classes and Scope Inner classes can access any variables in surrounding scope Caveats: Local variables must be final Can only use instance fields of surrounding scope if we re inside an instance method Example: Prompt user for what porridge tastes like

Key Layout Ideas JFrame s add(component c) method Adds a new component to be drawn Throws out the old one! JFrame also has method add(component c, Object constraint) Typical constraints: BorderLayout.NORTH, BorderLayout.CENTER Can add one thing to each direction, plus center JPanel is a container (a thing!) that can display multiple components

Repaint (and thin no more) To update graphics: We tell Java library that we need to be redrawn: drawcomponent.repaint() Library calls paintcomponent() when it s ready Don t call paintcomponent() yourself! It s just there for Java s call back.

Mouse Listeners public interface MouseListener { 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); }

So, how do we do this?

LinearLightsOut Work Time