SlideShare a Scribd company logo
1 of 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)

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 handlingPayal Dungarwal
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03Ankit 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 eventSoftNutx
 
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 IIIOXUS 20
 
Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2PRN USM
 
Adding a action listener to button
Adding a action listener to buttonAdding a action listener to button
Adding a action listener to buttonyugandhar 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 WPFQuang Nguyễn Bá
 
Intents in Android
Intents in AndroidIntents in Android
Intents in Androidma-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.pptxGood657694
 
event handling new.ppt
event handling new.pptevent handling new.ppt
event handling new.pptusama537223
 
engineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptengineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptsharanyak0721
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVASrajan 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 Intentadmin220812
 
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. 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
 
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 programmingSynapseindiappsdevelopment
 
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.pptxudithaisur
 

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
 
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
 

Recently uploaded

Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 

Recently uploaded (20)

Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.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.