0% found this document useful (0 votes)
13 views

Programming in Java-Week6

1. The document describes several event classes in Java including AdjustmentEvent, ComponentEvent, ContainerEvent, FocusEvent, InputEvent, ItemEvent, KeyEvent, MouseEvent, TextEvent, and WindowEvent. 2. Each event class defines integer constants that identify different types of events and includes constructors to specify event details like the source component and event type. 3. Listener interfaces are used to define components that listen for events, with methods invoked by the event source to handle different event types.

Uploaded by

adityapawar9692
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Programming in Java-Week6

1. The document describes several event classes in Java including AdjustmentEvent, ComponentEvent, ContainerEvent, FocusEvent, InputEvent, ItemEvent, KeyEvent, MouseEvent, TextEvent, and WindowEvent. 2. Each event class defines integer constants that identify different types of events and includes constructors to specify event details like the source component and event type. 3. Listener interfaces are used to define components that listen for events, with methods invoked by the event source to handle different event types.

Uploaded by

adityapawar9692
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

AdjustmentEvent Class

•An AdjustmentEvent is generated by a scroll bar.


•There are five types of adjustment events.
•The AdjustmentEvent class defines integer constants that can be
used to identify them.
•Example, ADJUSTMENT_VALUE_CHANGED, indicates that a
change has occurred.

•One AdjustmentEvent constructor: AdjustmentEvent(Adjustable


src, int id, int type, int val)
Here, src is a reference to the object that generated this event.
The id specifies the event. The type of the adjustment is
specified by type, and its associated value is val.

refer page 1110 of pdf,10 edition


ComponentEvent Class

•A ComponentEvent is generated when the size, position, or


visibility of a component is changed. There are four types of
component events.
•The ComponentEvent class defines integer constants that can be
used to identify them.

•ComponentEvent has this constructor:


ComponentEvent(Component src, int type)

Here, src is a reference to the object that generated this event.


The type of the event is specified by type.
ContainerEvent Class

•A ContainerEvent is generated when a component is added to or


removed from a container.
•There are two types of container events. : COMPONENT_ADDED
•and COMPONENT_REMOVED. They indicate that a component has
been added to or removed from the container.
•ContainerEvent is a subclass of ComponentEvent.
• Constructor:
ContainerEvent(Component src, int type, Component comp)
Here, src is a reference to the container that generated this
event. The type of the event is specified by type, and the
component that has been added to or removed from the
container is comp.
The FocusEvent Class

•A FocusEvent is generated when a component gains or loses input


focus.
•These events are identified by the integer constants
FOCUS_GAINED and FOCUS_LOST.
•FocusEvent is a subclass of ComponentEvent.
•One constructor:
FocusEvent(Component src, int type)
Here, src is a reference to the component that generated this
event. The type of the event is specified by type.

refer /read page 1113 of pdf,10 edition


The InputEvent Class

•The abstract class InputEvent is a subclass of ComponentEvent and


is the superclass for component input events.

•Its subclasses are KeyEvent and MouseEvent.

•InputEvent defines several integer constants that represent any


modifiers, such as the control key being pressed, that might be
associated with the event.
The ItemEvent Class

•An ItemEvent is generated when a check box or a list item is


clicked or when a checkable menu item is selected or deselected.

•There are two types of item events, which are identified by the
following integer constants:
DESELECTED
SELECTED

refer /read page 1115 of pdf,10 edition


The KeyEvent Class

•A KeyEvent is generated when keyboard input occurs.

• There are three types of key events, which are identified by these
integer constants: KEY_PRESSED, KEY_RELEASED, and KEY_TYPED.

•The first two events are generated when any key is pressed or
released.

•The last event occurs only when a character is generated.

refer /read page 1116 of pdf,10 edition


The MouseEvent Class

•MouseEvent is a subclass of InputEvent.


•One of its constructors:
•MouseEvent(Component src, int type, long when, int
modifiers, int x, int y, int clicks, boolean triggersPopup)
•Here, src is a reference to the component that generated the
event.
•The type of the event is specified by type.
•The system time at which the mouse event occurred is passed in
when.
•The modifiers argument indicates which modifiers were pressed
•when a mouse event occurred. The coordinates of the mouse are
passed in x and y.
•The click count is passed in clicks. The triggersPopup flag indicates
if this event causes a pop-up menu to appear on this platform.
The TextEvent Class

•Instances of this class describe text events.


•These are generated by text fields and text areas when characters
are entered by a user or program.
•TextEvent defines the integer constant TEXT_VALUE_CHANGED.
•The one constructor for this class is shown here:
TextEvent(Object src, int type)
•Here, src is a reference to the object that generated this event.
•The type of the event is specified by type.

refer /read page 1120 of pdf,10 edition


The WindowEvent Class

•There are ten types of window events.


•The WindowEvent class defines integer constants that can be used
to identify them.
•WindowEvent is a subclass of ComponentEvent. It defines several
constructors.
•The first is WindowEvent(Window src, int type)
•Here, src is a reference to the object that generated this event.
•The type of the event is type.

refer /read page 1121 of pdf,10 edition


Event Listener Interfaces

•The delegation event model has two parts: sources and listeners.
•listeners are created by implementing one or more of the
interfaces defined by the java.awt.event package.
•When an event occurs, the event source invokes the appropriate
method defined by the listener and provides an event object as its
argument.

refer /read page 1123-1145 of pdf,10 edition


Event Listener Interfaces

refer /read page 1123 of pdf,10 edition


References/Resources:

•Balaguruswamy, E. (2014). Programming with JAVA: A Primer. 5th


edition. India: McGraw Hill Education
•Horstmann, C. S. (2017). Core Java - Vol. I – Fundamentals (Vol. 10).
Pearson Education
•Schildt, H. (2018). Java: The Complete Reference. 10th edition. McGraw-
Hill Education.

NOTE: Please go through the reference book for details on the above
topic and feel free to mail your doubts or discuss anything. For
Introduction to AWT: Working with Windows, Graphics and Text, Please
use the following link:
https://www.javatpoint.com/java-awt
Assignment

Q1.Write different constants and their description available in


AdjustmentEvent class.
Q2.Write different constants and their description available in
ComponentEvent class.
Q3.Explain syntax of all constructors available in ContainerEvent and
FocusEvent class.
Q4.Write the name of constants present in InputEvent class.
Q5.List all the constants present in KeyEvent class.
Q6.List all the constants present in MouseEvent class.
Q7.List all the constants and their meaning present in WindowEvent
class.

You might also like