SlideShare a Scribd company logo
LISTENER INTERFACE METHODS
ActionListener actionPerformed()
AdjustmentListener adjustmentValueChanged()
ComponentListener componentResized()
componentMoved()
componentShown()
componentHidden()
ContainerListener componentAdded()
componentRemoved()
ActionEvent
An ActionEvent is generated when a button is pressed, a
list item is double-clicked, or a menu item is selected
 public String getActionCommand()
Returns the command string associated with this
action.
 int getModifiers()
Returns the modifier keys held down during this action
event.
 String paramString()
Returns a parameter string identifying this action event
Four integer constants
 public static final int ALT_MASK
The alt modifier. An indicator that the alt key was held down during the event.
 public static final int SHIFT_MASK
The shift modifier. An indicator that the shift key was held down during the event.
 public static final int CTRL_MASK
The control modifier. An indicator that the control key was held down during the
event.
 public static final int META_MASK
The meta modifier. An indicator that the meta key was held down during the event.
ActionListener Interface
This interface defines the actionPerformed() method
that is invoked when an action event occurs.
Its general form is shown here:
void actionPerformed(ActionEvent ae)
OUTPUT
 int getAdjustmentType( )
The amount of the adjustment can be obtained from the
getValue( ) method
 int getValue( )
For example, when a scroll bar is manipulated, this method returns
the value represented by that change.
AdjustmentListener Interface
This interface defines the adjustmentValueChanged( )
method that is invoked when an adjustment event occurs
public class AdjustmentListenerTest implements AdjustmentListener
{
Scrollbar sbar1 = new Scrollbar();
sbar1.addAdjustmentListener(this);
add(sbar1, "West");
Scrollbar sbar2=new Scrollbar();
add(sbar2,"East");
}
public void adjustmentValueChanged(AdjustmentEvent
AdjEvt)
{
System.out.println(AdjEvt.getValue());
}
}
ComponentEvent class
Indicates that a component moved, changed size, or
changed visibility.
This class has following constants.
 public static final int COMPONENT_MOVED
This event indicates that the component's position
changed.
 public static final int COMPONENT_RESIZED
This event indicates that the component's size changed.
 public static final int COMPONENT_SHOWN
This event indicates that the component was made visible.
 public static final int COMPONENT_HIDDEN
This event indicates that the component was become invisible.
ComponentListener interface
The listener interface for receiving component events.
 void componentResized(ComponentEvent e)
Invoked when the component's size changes.
 void componentMoved(ComponentEvent e)
Invoked when the component's position changes
 void componentShown(ComponentEvent e)
Invoked when the component has been made visible.
 void componentHidden(ComponentEvent e)
Invoked when the component has been made invisible.
import java.awt.*;
import java.awt.event;
public class ComponentEventExample1
{
public static void main(String[] args)
{
Frame frame = new Frame("ComponentEventExample");
TextArea txtArea = new TextArea();
Checkbox checkbox1 = new Checkbox("Checkbox 1");
Checkbox checkbox2 = new Checkbox("Checkbox 2");
frame.add(txtArea, BorderLayout.CENTER);
frame.add(checkbox1, BorderLayout.NORTH);
frame.add(checkbox2, BorderLayout.SOUTH);
frame.setVisible(true);
ComponentListener componentListener = new MyCompList();
frame.addComponentListener(componentListener);
}
}
class MyCompList implements ComponentListener
{
public void componentShown(ComponentEvent evt)
{
System.out.println("componentShown");
}
public void componentHidden(ComponentEvent evt)
{
System.out.println("componentHidden");
}
public void componentMoved(ComponentEvent evt)
{
System.out.println("componentMoved");
}
public void componentResized(ComponentEvent evt)
{
System.out.println("componentResized");
} }
ContainerEvent class
Indicates that a container's contents changed because a component
was added or removed
This class has following constants.
 public static final int COMPONENT_ADDED
This event indicates that a component was added to the
container.
 public static final int COMPONENT_REMOVED
This event indicates that a component was removed from the
container
ContainerListener interface
The listener interface for receiving container events
• 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.
Instance Methods
• getChild()
public Component getChild()
Returns the component that is being added or removed.
• getContainer()
public Container getContainer()
Returns the container that fired this event.
Event handling in Java(part 2)
Event handling in Java(part 2)
Event handling in Java(part 2)

More Related Content

What's hot

Advance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handlingAdvance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handling
Payal Dungarwal
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03
Ankit Dubey
 
Event handling63
Event handling63Event handling63
Event handling63myrajendra
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5sotlsoc
 
Java gui event
Java gui eventJava gui event
Java gui event
SoftNutx
 
12 High Level UI Event Handling
12 High Level UI Event Handling12 High Level UI Event Handling
12 High Level UI Event Handlingcorneliuskoo
 
JAVA GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART III
OXUS 20
 
Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2
PRN USM
 
Androd Listeners
Androd ListenersAndrod Listeners
Androd Listeners
ksheerod shri toshniwal
 
Adding a action listener to button
Adding a action listener to buttonAdding a action listener to button
Adding a action listener to button
yugandhar vadlamudi
 
Lesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPFLesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPF
Quang Nguyễn Bá
 
Android development session 2 - intent and activity
Android development   session 2 - intent and activityAndroid development   session 2 - intent and activity
Android development session 2 - intent and activity
Farabi Technology Middle East
 
25 awt
25 awt25 awt
25 awt
degestive
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
Tareq Hasan
 
Intents in Android
Intents in AndroidIntents in Android
Intents in Android
ma-polimi
 

What's hot (19)

Advance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handlingAdvance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handling
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03
 
Event handling
Event handlingEvent handling
Event handling
 
Event handling63
Event handling63Event handling63
Event handling63
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
 
Java gui event
Java gui eventJava gui event
Java gui event
 
12 High Level UI Event Handling
12 High Level UI Event Handling12 High Level UI Event Handling
12 High Level UI Event Handling
 
JAVA GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART III
 
Lecture8 oopj
Lecture8 oopjLecture8 oopj
Lecture8 oopj
 
Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2
 
What is Event
What is EventWhat is Event
What is Event
 
Androd Listeners
Androd ListenersAndrod Listeners
Androd Listeners
 
Adding a action listener to button
Adding a action listener to buttonAdding a action listener to button
Adding a action listener to button
 
Lesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPFLesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPF
 
Android development session 2 - intent and activity
Android development   session 2 - intent and activityAndroid development   session 2 - intent and activity
Android development session 2 - intent and activity
 
25 awt
25 awt25 awt
25 awt
 
Calculadora
CalculadoraCalculadora
Calculadora
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
Intents in Android
Intents in AndroidIntents in Android
Intents in Android
 

Similar to Event handling in Java(part 2)

event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
Good657694
 
event handling new.ppt
event handling new.pptevent handling new.ppt
event handling new.ppt
usama537223
 
engineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptengineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.ppt
sharanyak0721
 
Jp notes
Jp notesJp notes
Java awt
Java awtJava awt
Java awt
Arati Gadgil
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
shanmuga rajan
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVA
Srajan Shukla
 
Android Event and IntentAndroid Event and Intent
Android Event and IntentAndroid Event and IntentAndroid Event and IntentAndroid Event and Intent
Android Event and IntentAndroid Event and Intent
admin220812
 
Dr Jammi Ashok - Introduction to Java Material (OOPs)
 Dr Jammi Ashok - Introduction to Java Material (OOPs) Dr Jammi Ashok - Introduction to Java Material (OOPs)
Dr Jammi Ashok - Introduction to Java Material (OOPs)
jammiashok123
 
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
kashyapneha2809
 
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
nehakumari0xf
 
01 Java Is Architecture Neutral
01 Java Is Architecture Neutral01 Java Is Architecture Neutral
01 Java Is Architecture Neutralrajuglobal
 
Synapseindia dotnet development chapter 14 event-driven programming
Synapseindia dotnet development  chapter 14 event-driven programmingSynapseindia dotnet development  chapter 14 event-driven programming
Synapseindia dotnet development chapter 14 event-driven programming
Synapseindiappsdevelopment
 
openFrameworks 007 - events
openFrameworks 007 - eventsopenFrameworks 007 - events
openFrameworks 007 - eventsroxlu
 
Signalsで Event処理を簡単に
Signalsで Event処理を簡単にSignalsで Event処理を簡単に
Signalsで Event処理を簡単に
Hiroaki Okubo
 
ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptx
udithaisur
 
J query
J queryJ query
J query
bosco1303
 

Similar to Event handling in Java(part 2) (20)

event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
event handling new.ppt
event handling new.pptevent handling new.ppt
event handling new.ppt
 
Swing
SwingSwing
Swing
 
engineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptengineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.ppt
 
Jp notes
Jp notesJp notes
Jp notes
 
Java awt
Java awtJava awt
Java awt
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVA
 
Android Event and IntentAndroid Event and Intent
Android Event and IntentAndroid Event and IntentAndroid Event and IntentAndroid Event and Intent
Android Event and IntentAndroid Event and Intent
 
Swing
SwingSwing
Swing
 
Dr Jammi Ashok - Introduction to Java Material (OOPs)
 Dr Jammi Ashok - Introduction to Java Material (OOPs) Dr Jammi Ashok - Introduction to Java Material (OOPs)
Dr Jammi Ashok - Introduction to Java Material (OOPs)
 
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
 
01 Java Is Architecture Neutral
01 Java Is Architecture Neutral01 Java Is Architecture Neutral
01 Java Is Architecture Neutral
 
Synapseindia dotnet development chapter 14 event-driven programming
Synapseindia dotnet development  chapter 14 event-driven programmingSynapseindia dotnet development  chapter 14 event-driven programming
Synapseindia dotnet development chapter 14 event-driven programming
 
openFrameworks 007 - events
openFrameworks 007 - eventsopenFrameworks 007 - events
openFrameworks 007 - events
 
2011 07-hiyoko
2011 07-hiyoko2011 07-hiyoko
2011 07-hiyoko
 
Signalsで Event処理を簡単に
Signalsで Event処理を簡単にSignalsで Event処理を簡単に
Signalsで Event処理を簡単に
 
ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptx
 
J query
J queryJ query
J query
 

Recently uploaded

Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 

Recently uploaded (20)

Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 

Event handling in Java(part 2)

  • 1.
  • 2. LISTENER INTERFACE METHODS ActionListener actionPerformed() AdjustmentListener adjustmentValueChanged() ComponentListener componentResized() componentMoved() componentShown() componentHidden() ContainerListener componentAdded() componentRemoved()
  • 3.
  • 4. ActionEvent An ActionEvent is generated when a button is pressed, a list item is double-clicked, or a menu item is selected
  • 5.  public String getActionCommand() Returns the command string associated with this action.  int getModifiers() Returns the modifier keys held down during this action event.  String paramString() Returns a parameter string identifying this action event
  • 6. Four integer constants  public static final int ALT_MASK The alt modifier. An indicator that the alt key was held down during the event.  public static final int SHIFT_MASK The shift modifier. An indicator that the shift key was held down during the event.  public static final int CTRL_MASK The control modifier. An indicator that the control key was held down during the event.  public static final int META_MASK The meta modifier. An indicator that the meta key was held down during the event.
  • 7. ActionListener Interface This interface defines the actionPerformed() method that is invoked when an action event occurs. Its general form is shown here: void actionPerformed(ActionEvent ae)
  • 8.
  • 10.
  • 11.  int getAdjustmentType( ) The amount of the adjustment can be obtained from the getValue( ) method  int getValue( ) For example, when a scroll bar is manipulated, this method returns the value represented by that change.
  • 12.
  • 13. AdjustmentListener Interface This interface defines the adjustmentValueChanged( ) method that is invoked when an adjustment event occurs
  • 14. public class AdjustmentListenerTest implements AdjustmentListener { Scrollbar sbar1 = new Scrollbar(); sbar1.addAdjustmentListener(this); add(sbar1, "West"); Scrollbar sbar2=new Scrollbar(); add(sbar2,"East"); } public void adjustmentValueChanged(AdjustmentEvent AdjEvt) { System.out.println(AdjEvt.getValue()); } }
  • 15.
  • 16. ComponentEvent class Indicates that a component moved, changed size, or changed visibility. This class has following constants.  public static final int COMPONENT_MOVED This event indicates that the component's position changed.  public static final int COMPONENT_RESIZED This event indicates that the component's size changed.  public static final int COMPONENT_SHOWN This event indicates that the component was made visible.  public static final int COMPONENT_HIDDEN This event indicates that the component was become invisible.
  • 17. ComponentListener interface The listener interface for receiving component events.  void componentResized(ComponentEvent e) Invoked when the component's size changes.  void componentMoved(ComponentEvent e) Invoked when the component's position changes  void componentShown(ComponentEvent e) Invoked when the component has been made visible.  void componentHidden(ComponentEvent e) Invoked when the component has been made invisible.
  • 18. import java.awt.*; import java.awt.event; public class ComponentEventExample1 { public static void main(String[] args) { Frame frame = new Frame("ComponentEventExample"); TextArea txtArea = new TextArea(); Checkbox checkbox1 = new Checkbox("Checkbox 1"); Checkbox checkbox2 = new Checkbox("Checkbox 2"); frame.add(txtArea, BorderLayout.CENTER); frame.add(checkbox1, BorderLayout.NORTH); frame.add(checkbox2, BorderLayout.SOUTH); frame.setVisible(true); ComponentListener componentListener = new MyCompList(); frame.addComponentListener(componentListener); } }
  • 19. class MyCompList implements ComponentListener { public void componentShown(ComponentEvent evt) { System.out.println("componentShown"); } public void componentHidden(ComponentEvent evt) { System.out.println("componentHidden"); } public void componentMoved(ComponentEvent evt) { System.out.println("componentMoved"); } public void componentResized(ComponentEvent evt) { System.out.println("componentResized"); } }
  • 20.
  • 21. ContainerEvent class Indicates that a container's contents changed because a component was added or removed This class has following constants.  public static final int COMPONENT_ADDED This event indicates that a component was added to the container.  public static final int COMPONENT_REMOVED This event indicates that a component was removed from the container
  • 22. ContainerListener interface The listener interface for receiving container events • 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.
  • 23. Instance Methods • getChild() public Component getChild() Returns the component that is being added or removed. • getContainer() public Container getContainer() Returns the container that fired this event.