SlideShare ist ein Scribd-Unternehmen logo
1 von 26
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)

Weitere ähnliche Inhalte

Was ist angesagt?

Event handling63
Event handling63Event handling63
Event handling63
myrajendra
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
sotlsoc
 
12 High Level UI Event Handling
12 High Level UI Event Handling12 High Level UI Event Handling
12 High Level UI Event Handling
corneliuskoo
 
Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2
PRN USM
 

Was ist angesagt? (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
 

Ähnlich wie Event handling in Java(part 2)

01 Java Is Architecture Neutral
01 Java Is Architecture Neutral01 Java Is Architecture Neutral
01 Java Is Architecture Neutral
rajuglobal
 
openFrameworks 007 - events
openFrameworks 007 - eventsopenFrameworks 007 - events
openFrameworks 007 - events
roxlu
 
ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptx
udithaisur
 

Ähnlich wie 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
 
Signalsで Event処理を簡単に
Signalsで Event処理を簡単にSignalsで Event処理を簡単に
Signalsで Event処理を簡単に
 
2011 07-hiyoko
2011 07-hiyoko2011 07-hiyoko
2011 07-hiyoko
 
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
 

Kürzlich hochgeladen

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Kürzlich hochgeladen (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 

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.