All events are instances of event classes in the event class hierarchy. All classes in this hierarchy inherit from the
java.util.EventObject
class, and all classes in the AWT event hierarchy inherit from java.awt.AWTEvent
.
The subclasses of
AWTEvent
can be divided into two groups:- low-level events
- high-level (or semantic) events
- low-level events
- Low-level events are very specific user actions, such as clicking a button or moving a mouse.
- high-level (or semantic) events
- High-level, or semantic, events are more generalized or abstract events. They occur when a user chooses, selects, or alters something. High-level events are also known as semantic events because they abstract meaningful actions from sets of lower-level actions.
The ComponentEvent class contains five subclasses representing low-level events. These are
InputEvent
WindowEvent
FocusEvent
ContainerEvent
PaintEvent
InputEvent
InputEvent
is the root event class for all component-level input events. This class has two subclasses -MouseEvent
andKeyEvent
.
The three types of key events are key pressed, key released, and key typed. Each of these key events has a corresponding method and constant. You can use thegetKeyChar
method to return thechar
representing the key that has generated the event. Mouse events occur when a mouse button is pressed or released, or when a mouse is moved. TheMouseEvent
class also contains theMouseWheelEvent
class for mouse wheel rotation.WindowEvent
- Window events occur whenever a window
- is activated or deactivated
- is opened, closed, or closing
- is reduced to an icon or restored to a fully open state
- gains or loses focus
FocusEvent
- The two focus events are focus gained and focus lost. A component gains permanent focus when it makes a successful
requestFocus
method call or when users click or tab to access it. And it gains temporary focus as a side-effect of another operation, such as a window deactivation or scrollbar drag.
You distinguish between permanent and temporary focus using theisTemporary
method of theFocusEvent
:
public booleanisTemporary()
TheisTemporary
method returnstrue
if the focus was temporarily lost. ContainerEvent
- Container events occur when components are added to, or removed from, a container.
The registered container listener receives notification of an event and can obtain the identity of the new component using agetChild
method call. This allows containers to easily add input event listeners to, or remove them from, their components as each component is added or removed. PaintEvent
- Paint events are generated by the AWT, not delivered to any listeners. So they are of no practical use to programmers.
The four pre-defined subclasses representing semantic events are
ItemEvent
AdjustmentEvent
TextEvent
ActionEvent
ItemEvent
- Item events occur in components that have implemented the
ItemSelectable
interface. They represent the selection or deselection events on selectable items, such as lists, checkboxes, and pop-up menus.
Item events are generated byItemSelectable
objects, for exampleCheckbox
,List
,JComboBox
, andCheckboxMenuItem
. Rather than having to deal with individual mouse or click events, this high-level event is more meaningful and a listener can more easily deal with relevant events. AdjustmentEvent
- Adjustment events occur in components such as scrollbars, which have numeric values that can be incremented or decremented by the user.
For example, as a scrollbar is moved, its new position is signaled to an adjustment listener as an adjustment event. TextEvent
- Text events occur when text is entered, deleted, or edited in text entry fields.
ActionEvent
- Action events include such actions as clicking a button or pressing a function key. Several different user actions may result in the same action event being generated, which means that logically-related, higher-level events can be grouped together for handling in one place.
You can use theActionEvent
class'sgetActionCommand
method to distinguish between different types of the same semantic event.
All event types are represented as predefined constants in the different event classes to which they belong. For example, the
You can use the
MouseEvent
has constants for MOUSE_CLICKED
and MOUSE_RELEASED
, whereas for KeyEvent
there are such constants as KEY_PRESSED
.You can use the
AWTEvent
class getID
method to return one of these constants and so identify the type of event that has occurred.
5 comments:
good post. java training in chennai
Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article. thank you for sharing such a great blog with us.
rpa training in bangalore
rpa training in chennai
rpa training in pune
best rpa training in bangalore
Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.
Python training in bangalore
Python course in pune
Python training in bangalore
Good job in presenting the correct content with the clear explanation. The content looks real with valid information. Good Work
DevOps is currently a popular model currently organizations all over the world moving towards to it. Your post gave a clear idea about knowing the DevOps model and its importance.
Good to learn about DevOps at this time.
DevOps Training in Chennai
DevOps Course in Chennai
IDM speed is in actuality remarkable. You to situate the tempo of downloads to your hold preference. You will find currently numerous IDM Free Download are accessible and the IDM patch is accessible.. IDM Crack Download 64 Bit 2022
Post a Comment