EVENT-DRIVEN PROGRAMMING Subject:T0934 / Multimedia Programming Foundation Session:2 Tahun:2009 Versi:1/0.

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

JAVA API (GUI) Subject:T0934 / Multimedia Programming Foundation Session:1 Tahun:2009 Versi:1/0.
Event Handling.
Liang,Introduction to Java Programming,revised by Dai-kaiyu 1 Chapter 12 Event-Driven Programming 找出画中真谛 — 保罗. 塞尚.
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, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 15 Event-Driven Programming.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 14 Event-Driven Programming.
Events ● Anything that happens in a GUI is an event. For example: – User clicks a button, presses return when typing text, or chooses a menu item ( ActionEvent.
Event-Driven Programming Event:  A signal to the program that something has happened.  It can be triggered either by external user actions, such as mouse.
For IST410 Students only Events-1 Event Handling.
Event-Driven Programming
Unit 12 Object-oriented programming: Event-driven programming for GUI Jin Sa.
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.
Event-Driven Programming Outline Event and Event Source Event Types Listeners,Registerations,and Handling Events Event’s Declaration.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 16 Event-Driven Programming.
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.
1 Event-Driven Programming Just like designing GUIs, you also will probably not write Java code like the program examples given in these notes. You will.
GUI Programming in Java: Event Handling & More Components Corresponds with Chapter 14, Chapter 15.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
1 CSE 331 More Events (Mouse, Keyboard, Window, Focus, Change, Document...) slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Event Driven Programming, The.
More Event Handling Adapters Anonymous Listeners Pop menus Validating User Input.
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.
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.
CS-1020 Dr. Mark L. Hornick 1 Event-Driven Programming.
Anonymous Classes An anonymous class is a local class that does not have a name. An anonymous class allows an object to be created using an expression.
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.
© Marty Hall, Larry Brown Web core programming 1 Handling Mouse and Keyboard Events.
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.
Agenda Introduction. Event Model. Creating GUI Application. Event Examples.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 14 Abstract Classes.
THREAD Subject:T0934 / Multimedia Programming Foundation Session:3 Tahun:2009 Versi:1/0.
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.
Creating User Interfaces Event-Driven Programming.
Event-Driven Programming CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Event-Driven Programming F Procedural programming is executed in procedural order. F In event-driven programming, code is executed upon activation of events.
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.
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.
Event Handling and Listeners in SWING The practice of event handling.
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.
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.
Programming in Java Event Handling
GUI Event Handling Nithya Raman.
GUI Programming III: Events
CSE Software Engineering Fall 1999 Updated by J. Brown
Event-driven programming for GUI
Event Driven Programming
Chapter 16 Event-Driven Programming
Presentation transcript:

EVENT-DRIVEN PROGRAMMING Subject:T0934 / Multimedia Programming Foundation Session:2 Tahun:2009 Versi:1/0

Bina Nusantara Learning Outcomes In the end of this session, students must be able to: –Recognize Events and Listeners –Understand concept of Event-Driven Programming –Use Listeners in Java programming

Bina Nusantara Course Outlines Events Listeners ActionListener KeyListener MouseMotionListener WindowListener

Bina Nusantara Events A signal to the program that something has happened Triggered by external user actions (e.g. mouse movements, button clicks, keystrokes), or internal program activities (e.g. timer) Program can choose to respond or ignore Source object / component  on which an event is fired or generated

Events User ActionSource ObjectEvent Type Fired Click a buttonJButtonActionEvent Press return on text fieldJTextFieldActionEvent Select a new itemJComboBoxItemEvent, ActionEvent Select item(s)JListListSelectionEvent Click a check boxJCheckBoxItemEvent, ActionEvent Click a radio buttonJRadioButtonItemEvent, ActionEvent Select a menu itemJMenuItemActionEvent Move the scroll barJScrollBarAdjustmentEvent Window opened, closed, iconified, deiconified, or closing WindowWindowEvent Mouse pressed, released, clicked, entered, or exited ComponentMouseEvent Bina Nusantara

Events User ActionSource ObjectEvent Type Fired Mouse moved or draggedComponentMouseEvent Key released or pressedComponentKeyEvent Component added or removed from the container ContainerContainerEvent Component moved, resized, hidden, or shown ComponentComponentEvent Component gained or lost focusComponentFocusEvent Bina Nusantara

Listeners Java need 2 objects to rise Event-Driven –A source object fires an event, and an object interested in the event handles –The object that handles the event risen by the source object is called Listener Using Listener –Each listener handles different types of event risen by the source object –The listener object must be registered by the source object Example, in ActionEvent, use addActionListener() method –The event is written in respective listener method Example, in ActionEvent, use actionPerformed() method Bina Nusantara

Listeners EventsListenersMethods ActionEventActionListeneractionPerformed(ActionEvent) ItemEventItemListeneritemStateChanged(ItemEvent) MouseEventMouseListener MouseMotionListener mousePressed(MouseEvent) mouseReleased(MouseEvent) mouseEntered(MouseEvent) mouseExited(MouseEvent) mouseClicked(MouseEvent) mouseDragged(MouseEvent) mouseMoved(MouseEvent) KeyEventKeyListenerkeyPressed(KeyEvent) keyReleased(KeyEvent) keyTyped(KeyEvent) WindowEventWindowListenerwindowClosing(WindowEvent) windowOpened(WindowEvent) windowIconified(WindowEvent) Bina Nusantara

Listeners EventsListenersMethods WindowEventWindowListenerwindowDeiconified(WindowEvent) windowClosed(WindowEvent) windowActivated(WindowEvent) windowDeactivated(WindowEvent) ContainerEventContainerListenercomponentAdded(ContainerEvent) componentRemoved(ContainerEvent) ComponentEventComponentListenercomponentMovied(ComponentEvent) componentHidden(ComponentEvent) componentResized(ComponentEvent) componentShown(ComponentEvent) FocusEventFocusListenerfocusGained(FocusEvent) focusLost(FoucusEvent) AdjustmentEventAdjustmentListeneradjustmentValueChanged(Adjustment Event) Bina Nusantara

User Actions Bina Nusantara Actions: Press Key Click Mouse Click Button Select Menu Events: Key Event Mouse Event Action Event PROGRAM causes notify Listen Handle User respond action User click show

ActionListener Bina Nusantara A simple program to demonstrate Event Driven Programming Result

KeyListener show User pressed

KeyListener Bina Nusantara

KeyListener A simple program to show how to make a KeyListener Remember that, if you use a Listener, you MUST override all the listener methods Result Bina Nusantara

MouseMotionListener move drag click and hold

MouseMotionListener A simple program to show how to use MouseMotionListener Result Bina Nusantara

WindowListener

A simple program to show how to use WindowListener Result

Bina Nusantara References Introduction to Java Programming. 7ed. Liang Chapter 15. Event-driven Programming. Wikipedia ActionListener. Sun html html KeyListener. Sun ml ml MouseMotionListener. Sun istener.html istener.html WindowListener. Sun er.html er.html