0% found this document useful (0 votes)
4 views12 pages

Java Mouse Events Handling Guide

Uploaded by

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

Java Mouse Events Handling Guide

Uploaded by

darkdevil12366
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Handling Mouse Events in Java

(AWT)
• A Seminar on Java Event Handling
• By: [Your Name]
• Department of CSE
Introduction to Event Handling
• • Event Handling enables user interaction in
GUI programs.
• • Events are actions like mouse clicks or key
presses.
• • Java uses Delegation Event Model for event
handling.
Delegation Event Model
• Includes three parts:
• 1. Event Source – Object that generates the
event.
• 2. Event Object – Contains event details.
• 3. Event Listener – Receives and handles
events.
Mouse Events in Java
• Handled using [Link]
class.

• Common Events:
• • mouseClicked()
• • mousePressed()
• • mouseReleased()
• • mouseEntered()
• • mouseExited()
MouseListener Interface
• public interface MouseListener {
• void mouseClicked(MouseEvent e);
• void mousePressed(MouseEvent e);
• void mouseReleased(MouseEvent e);
• void mouseEntered(MouseEvent e);
• void mouseExited(MouseEvent e);
• }
Program Overview
• import [Link].*;
• import [Link].*;

• public class MouseEventDemo extends Frame


implements MouseListener {
• Label label;
• MouseEventDemo() {...}
• public void mouseClicked(...) {...}
• }
Program Explanation
• • Creates Frame window.
• • Adds Label component.
• • Implements MouseListener interface.
• • Each mouse method updates label text.
• • Displays coordinates on click.
How It Works
• 1. Mouse action triggers MouseEvent.
• 2. JVM creates MouseEvent object.
• 3. Event passed to MouseListener.
• 4. Corresponding method executes
automatically.
Output Example
• Action → Message
• • Click → Mouse Clicked at (x,y)
• • Press → Mouse Pressed
• • Release → Mouse Released
• • Enter → Mouse Entered
• • Exit → Mouse Exited
Real-Life Applications
• • Drawing/Paint Applications
• • Games (shooting, movement)
• • UI Controls & Tools
• • Drag-and-drop and graphic editors
Advantages
• • Makes GUI interactive
• • Modular and reusable
• • Follows OOP principles
• • Works with both AWT and Swing
Conclusion
• • Mouse Events handled via MouseListener
interface.
• • Java provides built-in event-driven
architecture.
• • Essential for GUI applications, games, and
tools.

• Thank You!

You might also like