Event Handling in Java: Alternatives and Patterns Raja Sooriamurthi www.kelley.iu.edu/raja Information Systems Department Kelley School of Business Indiana University, Bloomington Portions of this talk are from my presentation Prelude to the Java Event Model given at the 6th annual conference on Innovation and Technology in Computer Science Education (ITiCSE), June 2001, Canterbury, UK.
21
Embed
Event Handling in Java: Alternatives and Patterns Raja Sooriamurthi Information Systems Department Kelley School of Business Indiana.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Event Handling in Java: Alternatives and Patterns
Raja Sooriamurthi
www.kelley.iu.edu/raja
Information Systems DepartmentKelley School of Business
Indiana University, Bloomington
Portions of this talk are from my presentation Prelude to the Java Event Model given at the 6th annual conference on Innovation and Technology in Computer Science Education (ITiCSE), June 2001, Canterbury, UK.
Concepts
• Event handling
• Event handling models
• Inheritance vs delegation based models
• Notion of first class values
• Use of interfaces
• Callback methods
• Observable / Observer pattern
Learning is finding out what you already know.
--- Richard Bach
Event Handling
event sourceevent
listener
event object
event listener
event listener
Event Handling Models
• Giant Case Statement MS Windows, X-Windows
• Object Oriented Models
– Inheritance based MFC, Motif, Java 1.0– Delegation based Java 1.1
Giant Case Statement
case event of KEY_PRESS: action_1 MOUSE_CLICK: action_2 …end
• Extension => need to edit code
• No hierarchy of events
Problems:
Anatomy of a Button Object
label
color
handle code
Inheritance Based Event Model (Java 1.0)
class Button { // other state information and behavior // ... text // ... color // ... parent widget
boolean handleEvent() { System.out.println( "button has been clicked" ) ; return true; }}