Object-Oriented Programming with Java Lecture 2 The Java Event Model.

Slides:



Advertisements
Similar presentations
Event handling and listeners What is an event? user actions and context event sources and listeners Why should my programs be event- driven? User interaction.
Advertisements

Mari Göransson - KaU - Datavetenskap - DAVD11 1 Java Event Handling --
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
Component-Based Software Engineering Components and Interfaces Paul Krause.
Object-Oriented Programming with Java The Java Event Model Lecture 5.
Event Handling Events and Listeners Timers and Animation.
Object-Oriented Programming with Java Lecture 6 Using the Java Event Model.
1 Software Testing and Quality Assurance Lecture 26 (a) – Testing Interactions (Chapter 6)
Chapter 11 Exception Handling and Event Handling.
Unit 12 Object-oriented programming: Event-driven programming for GUI Jin Sa.
1 Gui Programming (Part I) Graphical User Interfaces (Part I) l Introduction to events. l A Brief history. l Event sources and listeners. l The delegation.
Components, interfaces, and re-entrance Taciana Amorim Vanderlei
Object-Oriented Analysis and Design
GUI Event Handling Nithya Raman. What is an Event? GUI components communicate with the rest of the applications through events. The source of an event.
Carnegie Mellon University MSCF1 C#/.NET Basics 2 Some code is from “C# in a Nutshell” and “Programming C#”
Internet Software Development The Java Event Model Lecture 5.
GUI Basics and Event- Driven Programming Feb 7, 2000.
Io package as Java’s basic I/O system continue’d.
A.k.a. GUI’s.  If you want to discuss your Lab 2 grade come see me this week. ◦ Office: 436 ERB. One hour prior to class ◦ Open to Appointments MWF 
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
Component-Based Software Engineering Using Interfaces Paul Krause.
Prepared by Fareeha Lecturer DCS IIUI 1 Windows API.
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
C H A P T E R T E N Event-Driven Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Carnegie Mellon University MSCF1 C#/.NET Basics 2 Some code is from “C# in a Nutshell”
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 14 Event-Driven Programming.
Dale Roberts GUI Programming using Java - Event Handling Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
1 Chapter Eleven Handling Events. 2 Objectives Learn about delegates How to create composed delegates How to handle events How to use the built-in EventHandler.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
Copyright © 2002, Systems and Computer Engineering, Carleton University EventModel.ppt * Object-Oriented Software Development Part 17.
Introduction to Java Beans CIS 421 Web-based Java Programming.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Cairngorm Microarchitecture. Pronunciation Cairngorm (kârn gôrm) n. yellowish-brown variety of quartz, especially found in Scottish Cairngorm mountain.
UID – Event Handling and Listeners Boriana Koleva
CS-1020 Dr. Mark L. Hornick 1 Event-Driven Programming.
Object Oriented Programming.  Interface  Event Handling.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 27 JavaBeans and.
Introduction to visual programming C#. Learning Outcomes In this chapter, you will learn about :  Event-Based Programming  The Event Based Model  Application.
GUIs Basic Concepts. GUI GUI : Graphical User Interface Window/Frame : a window on the screen Controls/Widgets : GUI components.
(1) Introduction to Java GUIs Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 15 Event-Driven Programming and.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 32 JavaBeans and Bean.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 15 Event-Driven Programming and.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Observer / Observable COMP 401 Fall 2014 Lecture 14 10/7/2014.
Java Beans - Basics CIS 421 Web-based Java Programming.
Java - hello world example public class HelloWorld { public static void main (String args[]) { System.out.println("Hello World"); }
Message Framework Topic subscribe for javascript/flex client.
Lesson 28: More on the GUI button, frame and actions.
Java Distributed Object Model A remote object is one whose methods can be invoked from another JVM on a different host. It implements one or more remote.
UQC117S2 Graphics Programming Lecture 2 Event Handling Program as a sequence of instructions Event -driven program Need to detect the event and carry out.
Events. Slide 2©SoftMoore Consulting Events Events are generated when a user interacts with the view objects of an application. Examples –button clicked–
MIT AITI 2004 Swing Event Model Lecture 17. The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the.
September 28, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser
.Net training In gandhinagar 16/10/2016.
Component-Based Software Engineering Components and Interfaces Paul Krause and Sotiris Moschoyiannis.
Chapter 32 JavaBeans and Bean Events
CSC 205 Programming II Lecture 5 AWT - I.
Events and Event Handling
Chapter 36 JavaBeans and Bean Events
Delegates and Events 14: Delegates and Events
Observer Design Pattern
Delegates & Events 1.
Seminarium on Component-based Software Engineering
Android Topics Asynchronous Callsbacks
Component-Based Software Engineering
Chapter 15 Event-Driven Programming and Animations Part 1
Events, Delegates, and Lambdas
Presentation transcript:

Object-Oriented Programming with Java Lecture 2 The Java Event Model

Callbacks and Events Contents  Callbacks  Events

 Pauls Pictures  Pauls Documents  Pauls Sums  Pauls Homework Problems  Pauls Pictures  Pauls Documents  Pauls Sums  Pauls Homework  Pauls ToDo Lists

 My Documents  Reports  Papers  Presentations Client Window Library File System Calls But I need to tell you something! Slide Shows I’m in charge here, guys!

Callbacks  Callbacks are used in procedural libraries when they need to handle asynchronous events  The alternative is for the client to continuously poll the library for events This is inefficient, especially if a large number of library components are registered with a client This is inefficient, especially if a large number of library components are registered with a client  But the use of callback means a client may observe “intermediate” states of a library “Classically” a library’s operations would run to completion before returning control “Classically” a library’s operations would run to completion before returning control

Call Sequence ClientaUserLibrary Client installs callback Third party calls library Library invokes callback “I need to tell you something!” “What’s happened?” “He’s changed a name!” Callback queries library “That’s cool” Callback returns Library returns

Directory Service public class Directory { public void addEntry(String name, File file) { // pre name != “” and file != null // post File file = map.get(name) } public void removeEntry(String name) { // pre name != “” // post map.get(name) = nil } public void registerNotifier(Notifier n) { // pre n != nil // post n registered, will be called on addEntry and removeEntry }

Callbacks and Events Contents  Callbacks  Events

Events  An abstraction of Callback that is applicable to “federations” of interacting components  The firing of an event is a way of one object telling one or more other recipients that something interesting has happened The sender fires an event The sender fires an event A recipient is called a listener and handles the event A recipient is called a listener and handles the event

Java Event Model Event Source Event Listener Register Event Listener Fire Event Event Object Event Object

Event Objects  Encapsulates information specific to an instance of an event  E.g. a “mouse click” event may contain: The position of the mouse pointer The position of the mouse pointer Which mouse button was clicked (and how many times) Which mouse button was clicked (and how many times)  The event object is passed as a parameter to the event notification method

Event Listeners  These are objects that need to be notified when a certain event occurs  Event notifications are made through method invocations in the listening object The event object is passed as a parameter The event object is passed as a parameter The event source must know which listener object(s) to call The event source must know which listener object(s) to call  This information is contained in an event- listener interface

Event Sources  Objects that fire events  Implements methods that allow listeners to: Register their interest in the events it generates; Register their interest in the events it generates; Unregister their interest in the events it generates. Unregister their interest in the events it generates.  Multicast event delivery enables an event to be fired to a number of event-listeners

Summary EventObject source getSource() toString() EventListener notification(evt) EventSource addListener() removeListener() fires passed to registers 0..* invokes notifications in0..*