Event Handling.

Slides:



Advertisements
Similar presentations
1 Event Listeners Some Events and Their Associated Event Listeners Act that Results in the EventListener Type User clicks a button, presses Enter while.
Advertisements

Mari Göransson - KaU - Datavetenskap - DAVD11 1 Java Event Handling --
Events and the AWT The objectives of this chapter are: To understand the principles of the Java 1.1 event model To understand how the event model is used.
Event-Driven Programming Thus far, our programs have been executed one statement after the other However, many programs depend on user actions to dictate.
Event Handling. In this class we will cover: Basics of event handling The AWT event hierarchy Semantic and low-level events in the AWT.
Event Handling Events and Listeners Timers and Animation.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 14 Event-Driven Programming.
Event-Driven Programming
Event Handling n Events: an event is an object that describes a state change in a source. n Event Sources: A source is an object that generates an event.
Graphics Programming with Inheritance Template pattern (Chap 6, se SceneEditor)
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.
Intermediate Java1 An example that uses inner classes Week Four Continued.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 16 Event-Driven Programming.
EVENTS CSC 171 FALL 2004 LECTURE 16. “Traditional” Input In console applications, user input is under control of the program The program asks the user.
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.
Io package as Java’s basic I/O system continue’d.
28-Aug-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic : Event Handling – GUI Part II.
Java GUI’s are event driven, meaning they generate events when the user interacts with the program. Typical events are moving the mouse, clicking a mouse.
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.
Event Handling Mohanraj S AP / IT Angel College of Engg & Tech.,
Graphical User Interface Components: Part 1 Chapter 11.
1 Outline 1 Introduction 2 Overview of Swing Components 3 JLabel 4 Event Handling 5 TextFields 6 How Event Handling Works 7 JButton 8 JCheckBox and JRadioButton.
COMP 321 Week 2. Outline Event-Driven Programming Events, Event Sources, Event Listeners Button and Timer Events Mouse Events, Adapters.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 12 Event-Driven Programming.
Event Handling. Event Driven Programming Flow of programs is determined by events. The Operating system recognizes events and passes them to the particular.
Event Handling. 2 GUIs are event driven –Generate events when user interacts with GUI e.g., moving mouse, pressing button, typing in text field, etc.
Introduction to Java Programming
Universidad Nacional de Colombia Facultad de Ingeniería Departamento de Sistemas ertificación en AVA.
CMSC 341 Making Java GUIs Functional. 09/29/2007 CMSC 341 Events 2 More on Swing Great Swing demo at /demos/jfc/SwingSet2/SwingSet2Plugin.html.
Lesson 6 Programming Techniques Event Handling /EvH/ AUBG ICoSCIS Team Assoc. Prof. Stoyan Bonev March, , 2013 SWU, Blagoevgrad.
Object Oriented Programming.  Interface  Event Handling.
Event Handling. The signals that a program receives from the operating system as a result of the actions are called events. A window based program is.
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Event-Driven Programming 1.
Agenda Introduction. Event Model. Creating GUI Application. Event Examples.
Index Event Handling Events Event Source Event Listener Event Classes Action Event Class Adjustment event Class Event Source Event Listener Interface Using.
GUI DYNAMICS Lecture 11 CS2110 – Fall GUI Statics and GUI Dynamics  Statics: what’s drawn on the screen  Components buttons, labels, lists, sliders,
Events in JAVA Needed for Applets and GUI based programs. Applet uses GUI to interact with user. Most of the events are generated by Mouse, Keyboard.
Event Handling. User actions are called “events” – Low-level window events Window changes – Low-level component events Mouse events, Keyboard events,
Event-Driven Programming CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
CS Lecture 04 Mice Lynda Thomas
Event-Driven Programming F Procedural programming is executed in procedural order. F In event-driven programming, code is executed upon activation of events.
Events (Chapter 11) Java Certification Study Group January 25, 1999 Mark Roth.
1 Event Handling – Lecture 4 Prepared by: Ahmad Ramin Rahimee Assistant Professor ICTI.
2/17/2016 DEPT OF CSE 1 EVENT HANDLING. 2/17/2016 DEPT OF CSE 2 Event handling is at the core of successful applet programming There are several types.
EVENT-DRIVEN PROGRAMMING Subject:T0934 / Multimedia Programming Foundation Session:2 Tahun:2009 Versi:1/0.
What Is an Event? Events – Objects that describe what happened Event sources – The generator of an event Event handlers – A method that receives an event.
Event Listeners ActionListener –button,list AdjustmentListener-scroll bar ComponentListener-when component hidden…. ContainerListener-comp added or removed.
1 Chapter 3 Event-Driven Programming. 2 Objectives F To explain the concept of event-driven programming (§12.2). F To understand event, event source,
CSI 3125, Preliminaries, page 1 Event Handling. CSI 3125, Preliminaries, page 2 Event Handling An Event Change in the state of an object is known as event.
Mouse Events GUI. Types of Events  Below, are some of the many kinds of events, swing components generate. Act causing EventListener Type User clicks.
UQC117S2 Graphics Programming Lecture 2 Event Handling Program as a sequence of instructions Event -driven program Need to detect the event and carry out.
TENTH LECTURE Event and listener. Events and Listeners An event can be defined as a type of signal to the program that something has happened. The event.
Dept. of CSIE, National University of Tainan 10/21/2012 Responding to User Input.
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit7: Event-driven programming 1.
GUI Programming using Java - Event Handling
CSC 205 Programming II Lecture 5 AWT - I.
Events and Event Handling
Chapter 14 Event-Driven Programming
Programming in Java, 2e Sachin Malhotra Saurabh Choudhary.
Chapter 12 Event-Driven Programming
Programming in Java Sachin Malhotra, Chairperson, PGDM-IT, IMS Ghaziabad Saurabh Chaudhary, Dean, Academics, IMS Ghaziabad.
GUI III IS
Programming in Java Event Handling
GUI Event Handling Nithya Raman.
GUI Programming III: Events
CSE Software Engineering Fall 1999 Updated by J. Brown
Chapter 16 Event-Driven Programming
Events, Event Handlers, and Threads
Making Java GUIs Functional
Presentation transcript:

Event Handling

Event Object that describes a state change in source e.g Pressing a Button generates Action Event [ Button is source of Event, Name of the event is Action] Every event has a source whose state change causes the event Some of the activities that may result in event generation: Pressing a Button Entering a Character from keyboard Selecting an item in a list Clicking the mouse Timer expires Counter Exceeds

Event Source Source is an object that generates an event Internal state of the source changes in some way When ever source generates an event it is notified to one or more listeners Source must register one or more listeners via following methods: public void addTypeListener(TypeListener el) public void addTypeListener(TypeListener el) throws java.util.TooManyListnersException Second Form allows only single listener to attached to the source. <<Type>> is the type of the Event

Event Listeners Object That is notified whenever source generates a particular type of event Responsibilities Must register with the source Must implement desired Listener interface

Delegation Event Model Modern Approach for event handling Three components Source [Object which generates the vent] Event [ Object that indicates state change in Source] Listener [ Notified Object which carries out some action whenever event is generated] Source generates a particular type of event and it notifies the listener On receiving notification from source listener carries out the desired task

Examples of Events ActionEvent (a) When Button is Pressed (b) When List Item is double-clicked (c) Menu Item is selected 2. AdjustmentEvent (a) Scroll Bar manipulated 3. ComponetEvent (a) Component is hidden, moved, resized or becomes visible 4. ContainerEvent (a) Whenever a component is added or removed from conatiner 5. FocusEvent (a) When ever component gains or lose keyboard focus 6 Mouse Event (a) Mouse Dragged , moved, clicked, pressed or released

Event Sources Examples User interface components that can generate events Button (ActionEvent) Checkbox (ItemEvent) Choice (ItemEvent) List (ActionEvent, ItemEvent) MenuItem (ActionEvent, ItemEvent) Scrollbar (AdjustmentEvent) Window (WindowEvent)

Event Classes EventObject (Super Class for for all events, java.util.*) AWTEvent (Subclass of EventObject, Superclass of all AWT based events) Package java.awt.event defines event classes Examples : ActionEvent, ContainerEvent, FocusEvent

Event Listener Interfaces Listener must implement suitable event listener interface in order to execute the code whenever that type of event is generated What happens when an event occus? Suitable Event object is created Source invokes the appropriate method provided by the listener by passing the object created in step1 as parameter Examples : ActionListener, MouseListner, MouseMotionListener

ActionListener Interface public interface ActionListener { public void actionPerformed(ActionEvent ae); }

MouseMotionListener extends MouseListener public interface MouseListener { public void mouseClicked(MouseEvent me); public void mouseEntered(MouseEvent me); public void mouseExited(MouseEvent me); public void mousePressed(MouseEvent me); public void mouseReleased(MouseEvent me); } MouseMotionListener extends MouseListener public interface MouseListener extends MouseMotionListener { public void mouseMoved(MouseEvent me); public void mouseDragged(MouseEvent me); }