1 / 4

Chapter 17: Handling Events

Chapter 17: Handling Events. Basics of Events Handling. The concept of event-driven programming in contrast with procedural programming Classes of Events: Low-level events such as moving the mouse of closing a window Semantic events (component-related events) such clicking a button

xia
Download Presentation

Chapter 17: Handling Events

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. Chapter 17: Handling Events

  2. Basics of Events Handling • The concept of event-driven programming in contrast with procedural programming • Classes of Events: • Low-level events such as moving the mouse of closing a window • Semantic events (component-related events) such clicking a button • Almost all event classes inherit from AWTEvent (found in java.awt) • You can handle events in two ways: • Using listeners (preferred) • Enabling events directly for objects • Example of the second approach: 1. Closing a Window\Sketcher • All event listener interfaces extend the interface java.util.EventListener

  3. Basics of Events Handling (Cont.) • You can implement a low-level event listener. Ex: 2. Low-level Event Listener • Implementing am adapter in the above case will avoid unnecessary code. Ex 3. Implementing an Adapter Class • To handle semantic events, there are three main classes: • ActionEvent: produced by buttons, menus, & text • ItemEvent: produced by JToggleButtons, JCheckBox, JMenuItem, etc. • AdjustementEvent: JScrollbar • Example: Lottery Applet • Handling low-level and semantic events. Ex: Adding a Mouse Listener

  4. Handling Semantic Events in Applications • Adding event listeners to the color and element menus. Ex: 6. Color Menu Listeners • The final form of the SketchFrame (9) • Adding Actions & tools bar • Tool tips • Disabling actions • Questions !!

More Related