CS 363 Comparative Programming Languages Logic Programming Languages.
Programming Languages
-
Upload
amber-trujillo -
Category
Documents
-
view
20 -
download
4
description
Transcript of Programming Languages
ProgrammingProgramming LanguagesLanguages
The Java Event ModelThe Java Event Model
In this lesson, we look at the content of In this lesson, we look at the content of these objects and how they are processed these objects and how they are processed in Java 2. in Java 2.
Events In Java 2 Events In Java 2
• Java 2 handles events that are generated in a Java 2 handles events that are generated in a graphical component by delegating to objects that graphical component by delegating to objects that have registered an interest in that type of event. have registered an interest in that type of event.
• Event observer objects are called listeners Event observer objects are called listeners and implement listener interfaces.and implement listener interfaces.
• The observable component that generates The observable component that generates events, and the observer is the object that events, and the observer is the object that has registered to receive events.has registered to receive events.
• The root of the Java 2 event hierarchy is the The root of the Java 2 event hierarchy is the EventObject classEventObject class
The Event Hierarchy The Event Hierarchy
• java.uti1.EventObject java.uti1.EventObject +-- +--java.awt.AWTEvent java.awt.AWTEvent +-- +-- java.awt.event.ActionEvent java.awt.event.ActionEvent +-- +-- java.awt.event.AdjustmentEvent java.awt.event.AdjustmentEvent +-- +-- java.awt.event.AncestorEvent java.awt.event.AncestorEvent +-- +-- java.awt.event.ComponentEvent java.awt.event.ComponentEvent +-- +-- java.awt.event.InputMethodEvent java.awt.event.InputMethodEvent +-- java.awt.event.InternalFrameEvent +-- java.awt.event.InternalFrameEvent +-- java.awt.event.InvocationEvent +-- java.awt.event.InvocationEvent
+-- java.awt.event.ItemEvent +-- java.awt.event.ItemEvent +-- java.awt.event.TextEvent +-- java.awt.event.TextEvent
Events that descend from Events that descend from ComponentEventComponentEvent
• java.awt.event.ComponentEvent java.awt.event.ComponentEvent +-- java.awt.event.ContainerEvent +-- java.awt.event.ContainerEvent +-- java.awt.event.FocusEvent +-- java.awt.event.FocusEvent
+-- java.awt.event.PaintEvent +-- java.awt.event.PaintEvent +-- java.awt.event.WindowEvent +-- java.awt.event.WindowEvent
+-- java. +-- java. awt.event.InputEvent awt.event.InputEvent +-- +-- java.awt.event.MouseEvent java.awt.event.MouseEvent +-- +-- java.awt.event.KeyEvent java.awt.event.KeyEvent
• For typical programming, user probably works For typical programming, user probably works with only a few of the events: ComponentEventwith only a few of the events: ComponentEvent
Listeners And Adapters Listeners And Adapters
• Each class that can generate one of these events Each class that can generate one of these events has a method to add a listener for that event.has a method to add a listener for that event.
• Java defines a number of listener interfaces that are Java defines a number of listener interfaces that are named according to the events they process. named according to the events they process.
• Java also includes classes called adapters Java also includes classes called adapters that provide empty methods for the more that provide empty methods for the more complex interfaces. complex interfaces.
Events, Listener interfaces, and Events, Listener interfaces, and Adapter classes. Adapter classes.
An Java Example with Event-An Java Example with Event-Handling Handling
• This Java Applet has a button, with caption “Click This Java Applet has a button, with caption “Click Me”. When user clicks the button, it beeps.Me”. When user clicks the button, it beeps.
An Java Example with Event-An Java Example with Event-Handling Handling