Mr G M Krishnapkshi Assistant Professor Department of Computer Science and IT Deogiri College Aurangabad DEOGIRI COLLEGEAURANGABAD EVENT HANDLING ByGM Krishnapakshi SUBJECTJAVA ID: 932682
Download Presentation The PPT/PDF document "EVENT HANDLING Presented by" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
EVENT HANDLING Presented byMr. G. M. KrishnapkshiAssistant ProfessorDepartment of Computer Science and IT.Deogiri College, Aurangabad
Slide2DEOGIRI COLLEGE,AURANGABADEVENT HANDLING By-G.M. KrishnapakshiSUBJECT-JAVA
Slide3Event handlingevent:- 1) An event is an object that describe a state change in a source. 2) Some of the activities that causes event to be generated are: i) Pressing a Button. ii) Entering a character through Key Board. iii) Selecting an item form a list etc.
Slide4Event delegation modelEvent delegation model means Events which are generated by Event Source for Event Receiver are processed by Event ListenerThere are two main types in Event Delegation Model 1) Event source 2) Event Listener
Receiver
Listener
Source
Event
Event
Slide51) EVENT SOURCE i) A source is an object that generates an event. ii) Event source is an object through which an action is to be generated . iii) Some general Event Source are 1) Button, CheckBox 2) List, MenusItem etc….. iv) Here is a general form for adding a listener to an event source:
public void addTypeListener(TypeEvent e)
* ‘Type’ is the name of the event.
* ‘e’ is the reference of the event listener
2) Event listener i) A listener is an object that is notified when an event occurs. ii) Event Listener are the object which is bind with a event sources and it carried out the event which was generated by Event Sources. iii) Example: MouseListener, KeyListner. iv)
MouseMotionListner interface
define two events.
a) When mouse is dragged.
b) When mouse is moved
v) For implementing event listener we have to import the following statement
import java.awt.event.*;
Slide7Example of event handlingimport java.applet.Applet;import java.awt.*;import java.awt.event.*;public class TextFiled extends Applet implements ActionListener{ int n,square; Label ll=new Label("Numbers"); TextField t=new TextField(5);
Button b=new Button(“Square");
Slide8public void init() { add(ll); add(t); add(b); b.addActionListener(this); } public void paint(Graphics g) { g.drawString("Square is="+square,20,50); }
public void actionPerformed(ActionEvent ae)
{
n=Integer.parseInt(t.getText());
square=n*n;
repaint();
}
}
Slide9Output:
Slide10Any question?
Slide11Thank you!!