1 / 9

Programming Languages

Programming Languages. The Java Event Model. In this lesson, we look at the content of these objects and how they are processed in Java 2. Events In Java 2.

Télécharger la présentation

Programming Languages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ProgrammingLanguages

  2. The Java Event Model In this lesson, we look at the content of these objects and how they are processed in Java 2.

  3. Events In Java 2 • Java 2 handles events that are generated in a graphical component by delegating to objects that have registered an interest in that type of event. • The observable component that generates events, and the observer is the object that has registered to receive events. • Event observer objects are called listeners and implement listener interfaces.

  4. The Event Hierarchy • The root of the Java 2 event hierarchy is the EventObject class • java.uti1.EventObject +--java.awt.AWTEvent +-- java.awt.event.ActionEvent +-- java.awt.event.AdjustmentEvent +-- java.awt.event.AncestorEvent +-- java.awt.event.ComponentEvent +-- java.awt.event.InputMethodEvent +-- java.awt.event.InternalFrameEvent +-- java.awt.event.InvocationEvent +-- java.awt.event.ItemEvent +-- java.awt.event.TextEvent

  5. Events that descend from ComponentEvent • For typical programming, user probably works with only a few of the events: ComponentEvent • java.awt.event.ComponentEvent +-- java.awt.event.ContainerEvent +-- java.awt.event.FocusEvent +-- java.awt.event.PaintEvent +-- java.awt.event.WindowEvent +-- java. awt.event.InputEvent +-- java.awt.event.MouseEvent +-- java.awt.event.KeyEvent

  6. Listeners And Adapters • Java defines a number of listener interfaces that are named according to the events they process. • Java also includes classes called adapters that provide empty methods for the more complex interfaces. • Each class that can generate one of these events has a method to add a listener for that event.

  7. Events, Listener interfaces, and Adapter classes.

  8. An Java Example with Event-Handling • This Java Applet has a button, with caption “Click Me”. When user clicks the button, it beeps.

  9. An Java Example with Event-Handling

More Related