SlideShare a Scribd company logo
1 of 65
What is Event?
Change in the state of an object is known as event i.e.
event describes the change in state of source.
Events are generated as result of user interaction with the
graphical user interface components.
For example, clicking on a button, moving the mouse,
entering a character through keyboard, selecting an item
from list, scrolling the page are the activities that causes an
event to happen.
Types of Event
 Foreground Events -
 Those events which require the direct interaction of user.
 They are generated as consequences of a person
interacting with the graphical components in Graphical
User Interface.
 For example, clicking on a button, moving the mouse,
entering a character through keyboard,selecting an item
from list, scrolling the page etc.
 Background Events -
 Those events that require the interaction of end user are
known as background events.
 Operating system interrupts, hardware or software
failure, timer expires, an operation completion are the
example of background events.
What is Event Handling?
Event Handling is the mechanism that
controls the event and decides what
should happen if an event occurs.
 This mechanism have the code which is
known as event handler that is executed
when an event occurs.
 Java Uses the Delegation Event Model
to handle the events. This model defines
the standard mechanism to generate and
handle the events.
Let's have a brief introduction to this
model.
The Delegation Event Model has the
following key participants namely:
 Source -
 The source is an object on which event occurs.
Source is responsible for providing information of
the occurred event to it's handler.
 Java provide as with classes for source object.
 Listener -
 It is also known as event handler.
 Listener is responsible for generating response to
an event.
 From java implementation point of view the listener
is also an object.
 Listener waits until it receives an event. Once the
event is received , the listener process the event an
then returns.
Steps involved in event handling
The User clicks the button and the event
is generated.
Now the object of concerned event class
is created automatically and information
about the source and the event get
populated with in same object.
Event object is forwarded to the method
of registered listener class.
the method is now get executed and
returns.
1.Action Keyword
This interface is used for receiving the
action event.
This interface defines the actionPerformed()
method that is invoked when an action
event occurs.
Method:
void actionPerformed(ActionEvent e)
2.Item Listener
 This interface is used for receiving the item
events.
 Method:

3.KeyEvent class
 This interface is used for receiving the key events.
Methods:
public void keyPressed(KeyEvent e)
The "key pressed" event. This event is generated
when a key is pushed down.
public void keyReleased(KeyEvent e)
The "key released" event. This event is generated
when a key is let up.
public void keyTyped(KeyEvent e)
The "key typed" event. This event is generated when
a character is entered.
4.Mouse Listener
 This interface is used for receiving the mouse event.
Methods:
public void mouseClicked(MouseEvent e) {…}
Called just after the user clicks the listened-to component.
public void mousePressed(MouseEvent e) {….}
Called just after the user presses a mouse button while the cursor is over
the listened-to component.
public void mouseReleased(MouseEvent e) {...}
Called just after the user releases a mouse button after a mouse press
over the listened-to component
public void mouseEntered(MouseEvent e) {…….}
Called just after the cursor enters the bounds of the listened-to
component.
public void mouseExited(MouseEvent e) {……..}
Called just after the cursor exits the bounds of the listened-to
component.
5.TextListener interface
The listener interface for receiving text
events.
Method:
public void textValueChanged(TextEvent e)
 Invoked when the value of the text has
changed.
 The code written for this method performs
the operations that need to occur when text
changes.
6.WindowListener interface
 This interface is used for receiving the window events.
Method:
 void windowActivated(WindowEvent e)
◦ Invoked when the Window is set to be the active Window.
 void windowDeactivated(WindowEvent e)
◦ Invoked when a Window is no longer the active Window.
 void windowClosed(WindowEvent e)
◦ Invoked when a window has been closed as the result of calling dispose
on the window
 void windowClosing(WindowEvent e)
◦ Invoked when the user attempts to close the window from the window's
system menu.
 void windowIconified(WindowEvent e)
◦ Invoked when a window is changed from a normal to a minimized state.
For many platforms, a minimized window is displayed as the icon
specified in the window's iconImage property.
 void windowDeiconified(WindowEvent e)
◦ Invoked when a window is changed from a minimized to a normal state.
 void windowOpened(WindowEvent e)
◦ Invoked the first time a window is made visible.
7.ContainerListener interface
The listener interface is used for receiving
container events.
Method:
 void componentAdded(ContainerEvent e)
◦ Invoked when a component has been added
to the container.
 void componentRemoved (ContainerEvent e)
◦ Invoked when a component has been
removed from the container.
8.MouseMotion Listener Interface
 This interface is used for receiving mouse
motion events.
Methods:
public void mouseDragged(MouseEvent e)
• It invokes when a mouse button is pressed on a
component and then dragged.
public void mouseMoved(MouseEvent e)
• It invokes when a mouse cursor has been
moved on to a component but no button has
been pushed.
 .
9.Focus Listener Interface
 This interface is used for receiving the focus
events methods.
Methods:
public void focusGained(FocusEvent e)
• It invokes when a component gains the keyboard
focus.
public void focusLost(FocusEvent e)
• It invokes when a component loss the keyboard
focus.
Adapter Class
 Adapters are used to replace the listeners.
 Adapter make event handling easy to the programmer.
 Every listener that includes more than one abstract
method has got a corresponding adapter class.
 The advantage of this adapter is that we can override
any one or two methods like instead of all.
 In case of a listener, we must override all the abstract
methods.
Example:
 The MouseListener interface has five
methods: mouseClicked(), mouseEntered(),
mouseExited(), mousePressed() and
mouseReleased().
 If in your program, you just need two
events: mouseEntered() and
mouseExited() that time you can use
adapter class for the mouseListener
interface.
 The adpter classes contain an empty
implementation for each method of the event
listener interface.
 To use the adapter class, you have to extend
that adapter class.
awt Adapters
{
Frame fr;
Label l1;
TextField t1;
public keyadapterdemo()
{
fr=new Frame("Key Adapter Example");
l1=new Label("Press button");
t1=new TextField();
fr.setSize(600,400);
fr.setLayout(null);
l1.setBounds(50,100,200,30);
t1.setBounds(300,100,200,30);
fr.add(l1);
fr.add(t1);
t1.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
System.out.println("you pressed "+e.getKeyChar());
}
}
);
fr.setVisible(true);
}
public static void main(String []args)
OUTPUT
Inner Class
 Inner classes are class within class.
 Inner class has special relationship with other class.
 The special relationship gives inner class access to
method of outer class as if they are the part of outer
class.
 Inner class instants or object has access to all method of
outer class (public, private and protected).
 As with instants methods and variables, an inner class is
associated with an instants of its enclosing class and has
direct access to that object methods and field also an
inner class is associated with an instances it can not
define any static members itself.
Syntax:
Class outerclass
{
class innerclass
{
……..
}
}
Example
Import java.io.*;
public class outer
{
int i=10;
public outer();
{
new inner();
System.out.println(“Inside outer class”);
}
Class inner
{
public inner()
{
System.out.println(“Inside inner class”);
System.out.print(“Value of outer class variable i=“+i);
}
}
public static void main(String [] args)
{
New outer();
}
}
What is Event

More Related Content

What's hot

What's hot (20)

Object Oriented Paradigm
Object Oriented ParadigmObject Oriented Paradigm
Object Oriented Paradigm
 
Android adapters
Android adaptersAndroid adapters
Android adapters
 
Event management
Event management Event management
Event management
 
Activity diagram model
Activity diagram modelActivity diagram model
Activity diagram model
 
Event handling
Event handlingEvent handling
Event handling
 
Event management ppt.
Event management ppt.Event management ppt.
Event management ppt.
 
UML Diagrams
UML DiagramsUML Diagrams
UML Diagrams
 
Event management
Event managementEvent management
Event management
 
Servlets
ServletsServlets
Servlets
 
Form Validation in JavaScript
Form Validation in JavaScriptForm Validation in JavaScript
Form Validation in JavaScript
 
EVENTS RISK MANAGEMENT SAFETY AND SECURITY
EVENTS RISK MANAGEMENT SAFETY AND SECURITYEVENTS RISK MANAGEMENT SAFETY AND SECURITY
EVENTS RISK MANAGEMENT SAFETY AND SECURITY
 
Introduction to .NET Framework
Introduction to .NET FrameworkIntroduction to .NET Framework
Introduction to .NET Framework
 
Introduction to Event Management
Introduction to Event ManagementIntroduction to Event Management
Introduction to Event Management
 
Event management
Event managementEvent management
Event management
 
Software estimation techniques
Software estimation techniquesSoftware estimation techniques
Software estimation techniques
 
college event managment system
college event managment system college event managment system
college event managment system
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
 
Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arrays
 
Event Management
Event ManagementEvent Management
Event Management
 
Asp.net state management
Asp.net state managementAsp.net state management
Asp.net state management
 

Viewers also liked

VIATRA 3: A Reactive Model Transformation Platform
VIATRA 3: A Reactive Model Transformation PlatformVIATRA 3: A Reactive Model Transformation Platform
VIATRA 3: A Reactive Model Transformation PlatformÁbel Hegedüs
 
Edgar Allan Poe - Selected Tales 1
Edgar Allan Poe - Selected Tales 1Edgar Allan Poe - Selected Tales 1
Edgar Allan Poe - Selected Tales 1George Grayson
 
Impactos de los cambios de uso de la Tierra sobre la Hidrología de los Páramo...
Impactos de los cambios de uso de la Tierra sobre la Hidrología de los Páramo...Impactos de los cambios de uso de la Tierra sobre la Hidrología de los Páramo...
Impactos de los cambios de uso de la Tierra sobre la Hidrología de los Páramo...InfoAndina CONDESAN
 
PR Hacks - Where to begin?
PR Hacks - Where to begin?PR Hacks - Where to begin?
PR Hacks - Where to begin?Cathy White
 
Web 3.0 And The Next Internet: New Directions And Opportunities For Scientifi...
Web 3.0 And The Next Internet: New Directions And Opportunities For Scientifi...Web 3.0 And The Next Internet: New Directions And Opportunities For Scientifi...
Web 3.0 And The Next Internet: New Directions And Opportunities For Scientifi...ajmalik
 
Concert Ton Kopmann
Concert Ton KopmannConcert Ton Kopmann
Concert Ton Kopmannupsantanyi
 
Escudos de nicaragua
Escudos de nicaraguaEscudos de nicaragua
Escudos de nicaraguayucetecom
 
2015 IEEE PROJECT TITLES FOR BE, B.TECH, ME, M.TECH, CSE, IT
2015 IEEE PROJECT TITLES FOR BE, B.TECH, ME, M.TECH, CSE, IT2015 IEEE PROJECT TITLES FOR BE, B.TECH, ME, M.TECH, CSE, IT
2015 IEEE PROJECT TITLES FOR BE, B.TECH, ME, M.TECH, CSE, ITJohn Britto
 
2016 january ohio yab meeting
2016 january ohio yab meeting2016 january ohio yab meeting
2016 january ohio yab meetingLisa Dickson
 
Charlotte Perkins Gilman - The Yellow Wallpaper 3
Charlotte Perkins Gilman - The Yellow Wallpaper 3Charlotte Perkins Gilman - The Yellow Wallpaper 3
Charlotte Perkins Gilman - The Yellow Wallpaper 3George Grayson
 
Trends in Digital Media Industry
Trends in Digital Media IndustryTrends in Digital Media Industry
Trends in Digital Media IndustryChargebee
 
Presentacion En Powerpoint Finalizada
Presentacion En Powerpoint FinalizadaPresentacion En Powerpoint Finalizada
Presentacion En Powerpoint FinalizadaMasMin
 

Viewers also liked (18)

VIATRA 3: A Reactive Model Transformation Platform
VIATRA 3: A Reactive Model Transformation PlatformVIATRA 3: A Reactive Model Transformation Platform
VIATRA 3: A Reactive Model Transformation Platform
 
Adding motion planning
Adding motion planningAdding motion planning
Adding motion planning
 
Edgar Allan Poe - Selected Tales 1
Edgar Allan Poe - Selected Tales 1Edgar Allan Poe - Selected Tales 1
Edgar Allan Poe - Selected Tales 1
 
Impactos de los cambios de uso de la Tierra sobre la Hidrología de los Páramo...
Impactos de los cambios de uso de la Tierra sobre la Hidrología de los Páramo...Impactos de los cambios de uso de la Tierra sobre la Hidrología de los Páramo...
Impactos de los cambios de uso de la Tierra sobre la Hidrología de los Páramo...
 
PR Hacks - Where to begin?
PR Hacks - Where to begin?PR Hacks - Where to begin?
PR Hacks - Where to begin?
 
Buling 3
Buling 3Buling 3
Buling 3
 
Web 3.0 And The Next Internet: New Directions And Opportunities For Scientifi...
Web 3.0 And The Next Internet: New Directions And Opportunities For Scientifi...Web 3.0 And The Next Internet: New Directions And Opportunities For Scientifi...
Web 3.0 And The Next Internet: New Directions And Opportunities For Scientifi...
 
Concert Ton Kopmann
Concert Ton KopmannConcert Ton Kopmann
Concert Ton Kopmann
 
Instituciones
InstitucionesInstituciones
Instituciones
 
Lecture #0 Intro
Lecture #0  IntroLecture #0  Intro
Lecture #0 Intro
 
Escudos de nicaragua
Escudos de nicaraguaEscudos de nicaragua
Escudos de nicaragua
 
2015 IEEE PROJECT TITLES FOR BE, B.TECH, ME, M.TECH, CSE, IT
2015 IEEE PROJECT TITLES FOR BE, B.TECH, ME, M.TECH, CSE, IT2015 IEEE PROJECT TITLES FOR BE, B.TECH, ME, M.TECH, CSE, IT
2015 IEEE PROJECT TITLES FOR BE, B.TECH, ME, M.TECH, CSE, IT
 
Green dao 3.0
Green dao 3.0Green dao 3.0
Green dao 3.0
 
2016 january ohio yab meeting
2016 january ohio yab meeting2016 january ohio yab meeting
2016 january ohio yab meeting
 
Charlotte Perkins Gilman - The Yellow Wallpaper 3
Charlotte Perkins Gilman - The Yellow Wallpaper 3Charlotte Perkins Gilman - The Yellow Wallpaper 3
Charlotte Perkins Gilman - The Yellow Wallpaper 3
 
Bosque Seco
Bosque  SecoBosque  Seco
Bosque Seco
 
Trends in Digital Media Industry
Trends in Digital Media IndustryTrends in Digital Media Industry
Trends in Digital Media Industry
 
Presentacion En Powerpoint Finalizada
Presentacion En Powerpoint FinalizadaPresentacion En Powerpoint Finalizada
Presentacion En Powerpoint Finalizada
 

Similar to What is Event

Event Handling in Java
Event Handling in JavaEvent Handling in Java
Event Handling in JavaAyesha Kanwal
 
tL20 event handling
tL20 event handlingtL20 event handling
tL20 event handlingteach4uin
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVASrajan Shukla
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03Ankit Dubey
 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024nehakumari0xf
 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024kashyapneha2809
 
Advance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handlingAdvance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handlingPayal Dungarwal
 
Java gui event
Java gui eventJava gui event
Java gui eventSoftNutx
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptxusvirat1805
 
java Unit4 chapter1 applets
java Unit4 chapter1 appletsjava Unit4 chapter1 applets
java Unit4 chapter1 appletsraksharao
 
Java eventhandling
Java eventhandlingJava eventhandling
Java eventhandlingArati Gadgil
 
ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxudithaisur
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in javaGoogle
 
engineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptengineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptsharanyak0721
 

Similar to What is Event (20)

Unit 6 Java
Unit 6 JavaUnit 6 Java
Unit 6 Java
 
Event Handling in Java
Event Handling in JavaEvent Handling in Java
Event Handling in Java
 
tL20 event handling
tL20 event handlingtL20 event handling
tL20 event handling
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVA
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03
 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
 
Event handling in Java(part 1)
Event handling in Java(part 1)Event handling in Java(part 1)
Event handling in Java(part 1)
 
Advance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handlingAdvance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handling
 
Java gui event
Java gui eventJava gui event
Java gui event
 
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing ButtonsJAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
 
Androd Listeners
Androd ListenersAndrod Listeners
Androd Listeners
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
Event handling
Event handlingEvent handling
Event handling
 
java Unit4 chapter1 applets
java Unit4 chapter1 appletsjava Unit4 chapter1 applets
java Unit4 chapter1 applets
 
Java eventhandling
Java eventhandlingJava eventhandling
Java eventhandling
 
ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptx
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
engineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptengineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.ppt
 
Java
JavaJava
Java
 

What is Event

  • 1. What is Event? Change in the state of an object is known as event i.e. event describes the change in state of source. Events are generated as result of user interaction with the graphical user interface components. For example, clicking on a button, moving the mouse, entering a character through keyboard, selecting an item from list, scrolling the page are the activities that causes an event to happen.
  • 2. Types of Event  Foreground Events -  Those events which require the direct interaction of user.  They are generated as consequences of a person interacting with the graphical components in Graphical User Interface.  For example, clicking on a button, moving the mouse, entering a character through keyboard,selecting an item from list, scrolling the page etc.  Background Events -  Those events that require the interaction of end user are known as background events.  Operating system interrupts, hardware or software failure, timer expires, an operation completion are the example of background events.
  • 3. What is Event Handling? Event Handling is the mechanism that controls the event and decides what should happen if an event occurs.  This mechanism have the code which is known as event handler that is executed when an event occurs.  Java Uses the Delegation Event Model to handle the events. This model defines the standard mechanism to generate and handle the events. Let's have a brief introduction to this model.
  • 4. The Delegation Event Model has the following key participants namely:  Source -  The source is an object on which event occurs. Source is responsible for providing information of the occurred event to it's handler.  Java provide as with classes for source object.  Listener -  It is also known as event handler.  Listener is responsible for generating response to an event.  From java implementation point of view the listener is also an object.  Listener waits until it receives an event. Once the event is received , the listener process the event an then returns.
  • 5. Steps involved in event handling The User clicks the button and the event is generated. Now the object of concerned event class is created automatically and information about the source and the event get populated with in same object. Event object is forwarded to the method of registered listener class. the method is now get executed and returns.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. 1.Action Keyword This interface is used for receiving the action event. This interface defines the actionPerformed() method that is invoked when an action event occurs. Method: void actionPerformed(ActionEvent e)
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16. 2.Item Listener  This interface is used for receiving the item events.  Method:
  • 17.
  • 18.
  • 19. 3.KeyEvent class  This interface is used for receiving the key events. Methods: public void keyPressed(KeyEvent e) The "key pressed" event. This event is generated when a key is pushed down. public void keyReleased(KeyEvent e) The "key released" event. This event is generated when a key is let up. public void keyTyped(KeyEvent e) The "key typed" event. This event is generated when a character is entered.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28. 4.Mouse Listener  This interface is used for receiving the mouse event. Methods: public void mouseClicked(MouseEvent e) {…} Called just after the user clicks the listened-to component. public void mousePressed(MouseEvent e) {….} Called just after the user presses a mouse button while the cursor is over the listened-to component. public void mouseReleased(MouseEvent e) {...} Called just after the user releases a mouse button after a mouse press over the listened-to component public void mouseEntered(MouseEvent e) {…….} Called just after the cursor enters the bounds of the listened-to component. public void mouseExited(MouseEvent e) {……..} Called just after the cursor exits the bounds of the listened-to component.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39. 5.TextListener interface The listener interface for receiving text events. Method: public void textValueChanged(TextEvent e)  Invoked when the value of the text has changed.  The code written for this method performs the operations that need to occur when text changes.
  • 40.
  • 41. 6.WindowListener interface  This interface is used for receiving the window events. Method:  void windowActivated(WindowEvent e) ◦ Invoked when the Window is set to be the active Window.  void windowDeactivated(WindowEvent e) ◦ Invoked when a Window is no longer the active Window.  void windowClosed(WindowEvent e) ◦ Invoked when a window has been closed as the result of calling dispose on the window  void windowClosing(WindowEvent e) ◦ Invoked when the user attempts to close the window from the window's system menu.  void windowIconified(WindowEvent e) ◦ Invoked when a window is changed from a normal to a minimized state. For many platforms, a minimized window is displayed as the icon specified in the window's iconImage property.  void windowDeiconified(WindowEvent e) ◦ Invoked when a window is changed from a minimized to a normal state.  void windowOpened(WindowEvent e) ◦ Invoked the first time a window is made visible.
  • 42.
  • 43. 7.ContainerListener interface The listener interface is used for receiving container events. Method:  void componentAdded(ContainerEvent e) ◦ Invoked when a component has been added to the container.  void componentRemoved (ContainerEvent e) ◦ Invoked when a component has been removed from the container.
  • 44.
  • 45. 8.MouseMotion Listener Interface  This interface is used for receiving mouse motion events. Methods: public void mouseDragged(MouseEvent e) • It invokes when a mouse button is pressed on a component and then dragged. public void mouseMoved(MouseEvent e) • It invokes when a mouse cursor has been moved on to a component but no button has been pushed.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.  .
  • 51. 9.Focus Listener Interface  This interface is used for receiving the focus events methods. Methods: public void focusGained(FocusEvent e) • It invokes when a component gains the keyboard focus. public void focusLost(FocusEvent e) • It invokes when a component loss the keyboard focus.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57. Adapter Class  Adapters are used to replace the listeners.  Adapter make event handling easy to the programmer.  Every listener that includes more than one abstract method has got a corresponding adapter class.  The advantage of this adapter is that we can override any one or two methods like instead of all.  In case of a listener, we must override all the abstract methods.
  • 58. Example:  The MouseListener interface has five methods: mouseClicked(), mouseEntered(), mouseExited(), mousePressed() and mouseReleased().  If in your program, you just need two events: mouseEntered() and mouseExited() that time you can use adapter class for the mouseListener interface.  The adpter classes contain an empty implementation for each method of the event listener interface.  To use the adapter class, you have to extend that adapter class.
  • 60. { Frame fr; Label l1; TextField t1; public keyadapterdemo() { fr=new Frame("Key Adapter Example"); l1=new Label("Press button"); t1=new TextField(); fr.setSize(600,400); fr.setLayout(null); l1.setBounds(50,100,200,30); t1.setBounds(300,100,200,30); fr.add(l1); fr.add(t1); t1.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { System.out.println("you pressed "+e.getKeyChar()); } } ); fr.setVisible(true); } public static void main(String []args)
  • 62. Inner Class  Inner classes are class within class.  Inner class has special relationship with other class.  The special relationship gives inner class access to method of outer class as if they are the part of outer class.  Inner class instants or object has access to all method of outer class (public, private and protected).  As with instants methods and variables, an inner class is associated with an instants of its enclosing class and has direct access to that object methods and field also an inner class is associated with an instances it can not define any static members itself.
  • 64. Example Import java.io.*; public class outer { int i=10; public outer(); { new inner(); System.out.println(“Inside outer class”); } Class inner { public inner() { System.out.println(“Inside inner class”); System.out.print(“Value of outer class variable i=“+i); } } public static void main(String [] args) { New outer(); } }