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

Slides:



Advertisements
Similar presentations
Event handling and listeners What is an event? user actions and context event sources and listeners Why should my programs be event- driven? User interaction.
Advertisements

Mari Göransson - KaU - Datavetenskap - DAVD11 1 Java Event Handling --
Event Handling Feb 14, Event Model Revisited zRecall that a component can fire an event. zEach type of event is defined as a distinct class. zAn.
Dale Roberts GUI Programming using Java - Mouse Events Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 9 Object Oriented Programming in Java Advanced Topics Abstract Windowing.
Event Handling Events and Listeners Timers and Animation.
CSE 115 Week 5 February , Monday Announcements Exam 3 today Exam 3 today Lab 3 due this week Lab 3 due this week Exam 4 Monday 2/18 Exam.
Chapter 11 Exception Handling and Event Handling.
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
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.
1 lecture 12Lecture 13 Event Handling (cont.) Overview  Handling Window Events.  Event Adapters Revisited.  Introduction to Components and Containers.
Object-Oriented Programming with Java Lecture 2 The Java Event Model.
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.
10.1 AWT The AWT classes Users today expect a Graphical User Interface (GUI) Improves application usability Difficult to implement cross-platform.
Programming Task: Task 1 Controlled Assessment Practice.
GUI Basics and Event- Driven Programming Feb 7, 2000.
Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler.
Meet Me on Mars Lesson 7 Variables and Messages. Events and Variables 1. Click the _________ button 2. When ________ clicked, set ______ to ____ 3. Now,
A.k.a. GUI’s.  If you want to discuss your Lab 2 grade come see me this week. ◦ Office: 436 ERB. One hour prior to class ◦ Open to Appointments MWF 
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Welcome to CIS 083 ! Events CIS 068.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
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.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
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.
1 Unit 5 GUI Aum Amriteshwaryai Namah. 2 Overview Shall learn how to reuse the graphics classes provided by Java for constructing Graphical User Interface.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 12 Event-Driven Programming.
Introduction to GUI Programming with Java Graphical User Interfaces With AWT and Swing Towson University *Ref:
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Computer Science [3] Java Programming II - Laboratory Course Lab 4: Common GUI Event Types and Listener Interfaces Layout Mangers Faculty of Engineering.
Creating a GUI with JFC/Swing. What are the JFC and Swing? JFC –Java Foundation Classes –a group of features to help people build graphical user interfaces.
UID – Event Handling and Listeners Boriana Koleva
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
Week 6: Basic GUI Programming Concepts in Java Example: JFrameDemo.java container : a screen window/applet window/panel that groups and arranges components.
Object Oriented Programming.  Interface  Event Handling.
SEEM3460 Tutorial GUI in Java. Some Basic GUI Terms Component (Control in some languages) the basic GUI unit something visible something that user can.
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.
Introduction to visual programming C#. Learning Outcomes In this chapter, you will learn about :  Event-Based Programming  The Event Based Model  Application.
Graphical User Interfaces. Graphical input and output with JOptionPane.
Event Handling. User actions are called “events” – Low-level window events Window changes – Low-level component events Mouse events, Keyboard events,
Creating User Interfaces Event-Driven Programming.
Lecture 18: Events; Cool Applets Yoni Fridman 7/30/01 7/30/01.
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.
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,
Java - hello world example public class HelloWorld { public static void main (String args[]) { System.out.println("Hello World"); }
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Event Handling CS 21a: Introduction to Computing I First Semester,
UQC117S2 Graphics Programming Lecture 2 Event Handling Program as a sequence of instructions Event -driven program Need to detect the event and carry out.
12-Jun-16 Event loops. 2 Programming in prehistoric times Earliest programs were all “batch” processing There was no interaction with the user Input Output.
Event Driven (Asynchronous) Programming. Event handling in Unity Subclass a class that contains event handling methods, and then override those methods.
Events and Event Handling
CompSci 230 S Programming Techniques
Aum Amriteshwaryai Namah
Event loops 16-Jun-18.
EE 422C Java FX.
Event loops.
Event loops 17-Jan-19.
Event loops 17-Jan-19.
Event loops 8-Apr-19.
Event loops.
Event loops.
Event loops 19-Aug-19.
Presentation transcript:

ProgrammingLanguages 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 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.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. Event observer objects are called listeners and implement listener interfaces.Event observer objects are called listeners and implement listener interfaces. The observable component that generates events, and the observer is the object that has registered to receive events.The observable component that generates events, and the observer is the object that has registered to receive events.

The root of the Java 2 event hierarchy is the EventObject classThe root of the Java 2 event hierarchy is the EventObject class The Event Hierarchy 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.TextEventjava.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

Events that descend from 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.KeyEventjava.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 For typical programming, user probably works with only a few of the events: ComponentEventFor typical programming, user probably works with only a few of the events: ComponentEvent

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

Events, Listener interfaces, and Adapter classes.

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

An Java Example with Event-Handling