Event Handling in Java CSE 470 - Software Engineering Spring 2000 By Prasad.

Slides:



Advertisements
Similar presentations
1 Graphical User Interface (GUI) Applications Abstract Windowing Toolkit (AWT) Events Handling Applets.
Advertisements

Programming in Java; Instructor:John Punin Graphics and Graphical User Interfaces1 Programming in Java Graphics and Graphical User Interfaces.
Event Handling.
Event-Driven Programming Thus far, our programs have been executed one statement after the other However, many programs depend on user actions to dictate.
June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 9 Object Oriented Programming in Java Advanced Topics Abstract Windowing.
Listener Interfaces  A mechanism for registering handlers that respond to external events  Motivation: Develop a Canvas class that:  supports drawing.
Mouse Events and Keyboard Events
Lecture 24 Applets. Introduction to Applets Applets should NOT have main method but rather init, stop, paint etc They should be run through javac compiler.
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.
James Tam An introduction into HCI: Task-Centered System Design An Introduction To Graphical User Interfaces The event-driven model Building a simple.
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.
CSE 331 Software Design & Implementation Dan Grossman Spring 2015 GUI Event-Driven Programming (Based on slides by Mike Ernst, Dan Grossman, David Notkin,
Io package as Java’s basic I/O system continue’d.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
CS 11 java track: lecture 4 This week: arrays interfaces listener classes inner classes GUI callbacks.
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.
7/3/00SEM107- © Kamin & ReddyClass 11 - Events - 1 Class 11 - Events r A couple of odds & ends m Component sizes  switch statement r Event types r Catching.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
MSc Workshop - © S. Kamin, U.Reddy Lect 4 - Events - 1 Lecture 4 – Event Handling r Painting r Event types r Catching different event types.
COMP 321 Week 2. Outline Event-Driven Programming Events, Event Sources, Event Listeners Button and Timer Events Mouse Events, Adapters.
Layout Managers Arranges and lays out the GUI components on a container.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 12 Event-Driven Programming.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
CS-1020 Dr. Mark L. Hornick 1 Event-Driven Programming.
Introduction to Java Programming
Understand the difference between applets and applications Identify meaningful applet resources for academic subjects Create and demonstrate a basic Java.
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.
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Event-Driven Programming 1.
Agenda Introduction. Event Model. Creating GUI Application. Event Examples.
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.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 10.
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.
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.
Java - hello world example public class HelloWorld { public static void main (String args[]) { System.out.println("Hello World"); }
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.
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit7: Event-driven programming 1.
Chapter 5: Enhancing Classes Presentation slides for Java Software Solutions Foundations of Program Design Second Edition by John Lewis and William Loftus.
GUI Programming using Java - Event Handling
Events and Event Handling
Chapter 14 Event-Driven Programming
CompSci 230 S Programming Techniques
Chapter 12 Event-Driven Programming
Web Design & Development Lecture 11
Lecture 09 Applets.
GUI III IS
CSE 331 Software Design & Implementation
CSE 331 Software Design & Implementation
CSE 331 Software Design and Implementation
Programming in Java Event Handling
Ellen Walker Hiram College
Event Handling CS 21a: Introduction to Computing I
GUI Event Handling Nithya Raman.
GUI Programming III: Events
CSE Software Engineering Fall 1999 Updated by J. Brown
Event-driven programming for GUI
CSE 331 Software Design and Implementation
Chapter 16 Event-Driven Programming
Events, Event Handlers, and Threads
Making Java GUIs Functional
CSE 331 Software Design & Implementation
Presentation transcript:

Event Handling in Java CSE Software Engineering Spring 2000 By Prasad

Introduction to Java.. n Java, platform independent language n Two types of programs in Java Applets (embedded in web pages) Command line programs n We are primarily interested in developing GUIs in Java and in Event Handling mechanisms of Java

To Compile and run Java Applets … n Include path setenv PATH {$PATH}:/usr/java1.2/bin in your.personal file n To compile Java programs javac programfile.java n To run Java applets appletviewer programfile.html n A sample programfile.html is given in next slide

Running Java applets continued..

Event Model of Java n Java uses delegation event Model Event Source Event Listener Ex: Button, Canvas, Text Box An object of a class that will implement methods which will respond to events Register with source Event Object e

Event Listeners … n Event Listener Object has to implement a event listener interface. n Examples of Event Listener interfaces: Action Listener Interface Mouse Listener Interface Mouse Motion Listener Interface n Examples: Class mylistener implements ActionListener { /* The following procedure is called when a Button is pressed. */ public void actionPerformed ( ActionEvent e ) { ……} }

Event Listeners contd …. Class mylistener implements MouseListener { /* Called when the mouse button is clicked */ public void mouseClicked(MouseEvent evt) { ….} /* Called when the mouse button is depressed */ public void mousePressed(MouseEvent evt) { …..} /* Called when the mouse button is released */ public void mouseReleased(MouseEvent evt) { …..} }

Event Object n Event Objects carry information about the event. Event Listeners get information from Event sources thru Event Objects. n Examples : MouseEvent Evt Evt.getX() --- gets the X-coordinate of mouse click. Evt.getY() --- gets the Y-coordinate of mouse click Evt.getSource() --- gets the source object of the mouse click event like a button

Event Registration …. n A Listener Object needs to register itself with an Event Source to be able to catch events on it. n Example: Button1.addActionListener( new mylistener1() ) Button1.addMouseListener( new mylistener2() ) n Multiple Listeners can listen to a single event source n A single Listener can listen to multiple event sources

Example -- Simple Action Event public class SimpleEvent extends Applet { Button button1 = new Button("Press me"); public void init() { this.add(button1); button1.addActionListener(new mylistener()); } Class mylistener implements ActionListener { public void actionPerformed(ActionEvent e) { if(e.getSource() == button1) { button1.setLabel("Again"); }

References n G. Cornell and C. Horstmann, “Core Java”, The Sunsoft Press Java Series, Second Edition, 1997 n D. Joshi, L. Lemay, and C. Perkins, “Teach yourself Java in Café in 21 days”, Sams.net publishing, 1996 n The Java Tutorial n D. Geary and A. McClellan, “Graphic Java”, The Sunsoft Press Java Series, 1997