
Quick Contact
Java Tutorial
- What is Java?
- History of Java
- Hello Java Program
- Features of Java
- Basic Syntax
- Java Setup
- Data Types in Java
- Java Variables
- Operators in Java
- JVM
- Java If-else Statement
- Switch Case Statement
- Java Loops
- Do-While Loop
- Java While Loop
- Continue Statement
- Break Statement in Java
- Constructors in Java
- Oops Concept in Java
- Features of OOPs
- Inheritance
- Exeception handeling
- Aggregation (HAS-A relationship) in Java
- Method Overriding in Java
- Method Overloading
- Java Static Keyword
- Java This Keyword
- Java Final Keyword
- Polymorphism
- Static Binding and Dynamic Binding
- Abstract class in Java
- Access Modifiers in Java
- Difference between abstract class and interface
- Interface in Java
- Garbage Collection in Java
- Java Package
- Encapsulation
- Serialization and Deserialization in Java
- Java Inner Classes
- Java Applets
- Multithreading in Java
- Thread Priorities in Java
- Thread Creation
- Inter Thread Communication
- Wrapper Classes in Java
- Java Input Output
- Java AWT Introduction
- Java Layout Manager
- Java Layout Policy
- Java AWT Events
- Collection Framework
- Collection Framework List Interface
- Swing in Java
- Swing Utility Classes
- Swing Layout Managers
- Java JDBC
- Hibernate Framework Overview – Architecture and Basics
Springboot
- Spring Environment Setup
- Spring Boot CRUD REST API Project using IntelliJ IDEA | Postman | MySQL
- Dockerizing Spring Boot Application | Spring Boot Docker Tutorial
- spring-boot-restapidocumentation with swagger
- Spring Boot HttpClient Overview
- Apache HttpClient POST HTTP Request Example
- Apache HttpClient PUT HTTP Request Example
- Apache HttpClient DELETE HTTP Request Example
- Apache HttpClient HTML Form POST Request Example
- Spring Boot JSP Exampl
- Deploying Spring Boot WAR file with JSP to Tomcat
- Spring Boot Annotations
- Spring Core Annotations
- Spring MVC Annotations with Examples
- Spring Scheduling Annotations
- Spring - Java-based Container Configuration
- Spring Java Based Configuration Example
Hibernate
- Hibernate 5 hello world
- Hibernate- One to One Unidirectional Mapping Annotation Example
- Hibernate - Batch Processing
- Hibernate - Interceptors
- Hibernate 5 - Create, Read, Update and Delete (CRUD) Operations Example
- Hibernate Transaction Management
- Hibernate One to Many Unidirectional Mapping Example
- Hibernate One to Many Bidirectional Mapping Example
- Hibernate Many to Many Annotation Mapping Example
- Hibernate Primary KeyJoin Column
- Hibernate First Level Cache with Example
- Hibernate XML Configuration Example with Maven + Eclipse + MySQL Database
- Hibernate Java Configuration Example
- JPA 2 with Hibernate 5 Bootstrapping Example
- JPA and Hibernate Cascade Types
- Hibernate/JPA - Primary Key Generation
- Hibernate 5 - Enum Type Mapping Example
- Hibernate Component Mapping
- Hibernate Object States – Transient,Persistent and Detached
- Hibernate 5 - Save an Entity Example
- Hibernate 5 - Persist an Entity Example
- Hibernate 5 - saveOrUpdate() Method Example
- Hibernate 5 - get(), load() and byId() Method Examples
- Hibernate 5 - merge() Example
- Hibernate 5 - Delete or Remove an Entity Example
- Hibernate 5 - load() Method Example
- Hibernate Session Interface Methods
- Hibernate Session.clear() Method Example
- Introduction Of Java strutes to Architecture
- Struts 2 - Architecture
- Struts 2 - Configuration Files
- Struts 2 - Actions
- Struts 2 - Interceptors
- Struts 2 - Results & Result Types
- Struts 2 - Value Stack/OGNL
- Struts 2 - File Uploading
- Struts 2 - Database Access
- Struts 2 - Validations Framework
JAVA FX
- JavaFX Tutorial
- Introduction to JavaFX Pane
- JavaFX Popup
- JavaFX group
- JavaFX Controller
- JavaFX Gradient Color
- JavaFXAnchorPane
- JavaFXTabPane
- JavaFX Scene
- JavaFX Stage
- JavaFXWebView
- JavaFX Timeline
- JavaFX Timer
- JavaFX Image
- JavaFX Background
- JavaFX dialog
- JavaFX Font
- JavaFXTextArea
- JavaFXObservableList
- JavaFX GUI
- JavaFX FXML
- JavaFXEventHandler
- JavaFXGradle
- JavafxScrollpane
- JavaFXAPI
Java AWT EVENTS
Introduction
When a normal Java program (which is not GUI based) needs input, it prompts the user and then calls some input method, such as readline() i.e. the interaction is initiated by the program. This is not the way in which gui-based programs behave. The user initiates interaction with the program rather than program initiating the action.
For example, in a word processing software, user initiates action by clicking on different buttons, which generates an event and some piece of code is executed as a result and accordingly some action takes place. The clicking on save button will invoke the method which saves the contents to a file.
Interface | Event(Methods) | class | Methods |
---|---|---|---|
ActionListener | actionPerformed() | ActionEvent ae | getSource |
ItemListener | itemStateChanged() | ItemEvent ie | getItem |
AdjustmentListener | adjustmentValueChanged() | AdjustmentEvent ae | getAdjustable() |
MouseListener | mouseEntered | MouseEvent me | getX() |
MouseAdapter | mouseExited | getY() | |
mouseClicked | getPoint() | ||
mousePressed | getClickCount() | ||
mouseReleased | getButton() | ||
getModifiersEx() | |||
getModifiersExText() | |||
MouseMotionListener | mouseMoved | MouseEvent me | same as prev. |
MouseMotionAdapter | mouseDragged | ||
KeyListener | keyTyped | KeyEvent ke | getKeyChar() |
KeyAdapter | keyPressed | getKeyCode() | |
keyReleased | |||
FocusListener | focusGained | FocusEvent fe | getSource() |
FocusAdapter | focusLost | ||
WindowListener | windowOpend | WindowEvent we | |
WindowAdapter | windowClosing | ||
windowClosed | |||
windowActivated | |||
windowDeactivated | |||
windowIconified | |||
windowDeiconified |
Java uses event delegation model for event handling. In the event delegation model a component may be told which object or should be notified when the component generates a particular kind of event.
If a component is not interested in an event type, then events of that type will not be propagated. The delegation model is based on the following key concepts:
- Event classes.
- Event listeners.
- Adapters.
Event classes:
Clicking on a button results in an event. The event has lot of information associated with it, like: time, component generating the event, co-ordinates of the point at which clicking took place etc.
This information is put inside an event class. The concept is similar to exception handling. Whenever an exception occurs an object of appropriate exception class is created and all the exception related information is put into this object.
We have hierarchy of event classes, which is somewhat similar to the hierarchy of exception classes. Whenever some event occurs, it is detected by event handling, mechanism, which creates objects of appropriate event class and puts all the event related information into it.
Event listeners:
Event listeners are responsible for taking appropriate action when an event occurs. An event listener is an object to which a component has delegated the task of handling a particular kind of event.
When the component experiences input, an event of the appropriate type is constructed, the event is then passed as the parameter to a method call on the listener. A listener must implement the interface that contains that event handling method.
We can compare the event listeners with the catch blocks for handling the exceptions. We need to provide a catch block corresponding to the exception to be handled. Similarly if we want to handle an event generated by some component, we need to provide appropriate listener.
The listeners are associated with the components. Different events have different listeners. When event occurs, an appropriate listener method is called and event object is passed as parameter.
Adapters:
The listeners defined in the language are interfaces only. We need to provide implementation of the appropriate listener. Some listeners have 2 or more methods.
To implement a listener having more than one method, we need to provide implementation of all the methods even if we are interested only in one method. The adapter classes provide the solution to this problem.
An adapter class provides dummy implementation of all the methods of a listener. This helps in reducing programming efforts. If we want to use just one method of a listener class containing say 5 methods then we can simply extent the adapter class and override the desired method.
Event hierarchy:
The AWT has a well-defined event hierarchy. Normally the classes corresponding to leaf nodes in the event hierarchy represent the actual events. While non-leaf classes act as base classes and encapsulate.
AWT event hierarchy is described in the following diagram.

The java.util.eventObject class:
This is the top most super class of all the event classes. It is a very general class, with only one method of interest, which returns the object that originated the event.
Object getsource()
The java.awt.AWTEvent Class:
One sub class of event object is java.awt.AWTEvent, which is the super class of all the delegation model event classes. Again, there is only one method of interest, which return the id of the event.
int getID()
An event’s ID is an int that specifies the exact nature of the event. For example, an instance of the mouseevent class can represent one of seven occurrences: click , Drag, Entrance, Move, Exit, Press, Release. Each of these possibilities is represented by an int MouseEvent . MOUSE_CLICKED, MouseEvent.MOUSE_DRAGGED, and so on.
The sub classes of java.awt.AWTEvent represent the various event types that can be generated by the various AWT components, and contain all necessary information relating to the activity that triggered the event.
The non-super class event types (i.e. those that are actually fired by component) are:
-
ActionEvent:
general by activation of components for example .it is generated on button click, on double-click on list item and on pressing enter in a TextField.
-
AdjustmentEvent:
generated by adjustment of adjustable components such as scroll bars.
-
ContainerEvent:
generated when components are added to or removed from a container.
-
FocusEvent:
generated when a component receives or loses input focus.
-
ItemEvent:
generated when an item is selected from a list, choice, or checkbox.
-
KeyEvent :
generated by keyboard activity.
-
MouseEvent:
generated by mouse activity.
-
MouseWheelEvent
An event, which indicates that the mouse wheel was rotated in a component.
-
WindowEvent:
generated by window activity (such as iconifying or deiconifying.)
-
TextEvent:
generated when a text component is modified.
The java.awt.event package:
This package provides the interfaces and classes for dealing with different types of events fired by AWT components. The events are fired by event sources. An event listener registers with an event source to receive notifications about the events of a particular type.
This package defines events and event listeners, as well as event listener adapters, which are convenience classes to make easier the process of writing event listeners.
Event Listener Interfaces:
Each event class has a corresponding listener interface and defines one or more methods. The most commonly used listener interfaces are described in the following sections.
The Action Listener Interface:
This is the listener interface for receiving action events. The class that is interested in processing an action event implement this interface, and the object created with that class is registered with a component, using the component’s addActionListener() method. When the action event occurs, the action listener’s action performed () method is invoked whose signatures are:
Apply now for Advanced Java Training Course