A comprehensive, interactive learning application for understanding all Java Swing event handlers and listeners.
This application demonstrates 30+ event listener interfaces with 70+ methods in a hands-on, educational environment. Perfect for students, educators, and developers learning Java GUI programming.
- Real-time Event Logging: See exactly which listener fires, which method is called, and what data is passed
- Comprehensive Documentation: Every listener includes detailed comments explaining:
- What triggers the event
- When to use it
- Common use cases
- Example implementations
- Interactive Components: All UI elements are designed to demonstrate their associated events
- Organized Layout: 6 themed tabs categorizing events by functionality
- β
ActionListener- Button clicks, menu selections, Enter key actions - β
ItemListener- Checkbox, radio button, combobox state changes - β
ChangeListener- Slider, spinner, progress bar value changes - β
ListSelectionListener- JList selection changes - β
ButtonModel ChangeListener- Advanced button state tracking
- β
MouseListener(5 methods) - Click, press, release, enter, exit - β
MouseMotionListener(2 methods) - Drag and move tracking - β
MouseWheelListener- Mouse wheel scroll events - β
KeyListener(3 methods) - Key press, release, and typed
- β
FocusListener(2 methods) - Focus gained/lost - β
ComponentListener(4 methods) - Resize, move, show, hide - β
ContainerListener(2 methods) - Component add/remove - β
HierarchyListener- Component hierarchy changes - β
AncestorListener(3 methods) - Ancestor add, remove, move
- β
WindowListener(7 methods) - Open, close, iconify, activate, etc. - β
WindowFocusListener(2 methods) - Window focus gained/lost - β
WindowStateListener- Window state changes (minimize, maximize) - β
InternalFrameListener(7 methods) - Internal frame lifecycle
- β
TreeSelectionListener- JTree node selection - β
TreeExpansionListener(2 methods) - Tree expand/collapse - β
TreeWillExpandListener(2 methods) - Pre-expansion veto capability - β
TableModelListener- Table data changes - β
MenuListener(3 methods) - Menu selected, deselected, canceled - β
PopupMenuListener(3 methods) - Popup visibility and cancel - β
PropertyChangeListener- Bean property changes
- β
DocumentListener(3 methods) - Text insert, remove, attribute changes - β
UndoableEditListener- Undoable edit tracking - β
CaretListener- Text caret position changes - β
HyperlinkListener- Hyperlink interactions
- Event Counter: Track the total number of events fired
- Timestamps: See when each event occurred
- Clear Log Function: Reset the event log anytime
- Test Windows: Create separate windows to test window events
- Dynamic Components: Add/remove components to see container events
- Modern UI: Clean, professional interface with FlatLaf theme
Download the latest installer for your platform from our Releases page. These installers include Java Runtime Environment (JRE) 21, so no separate Java installation is needed!
Windows
- Download
EventListenersDemo-windows.exe - Run the installer
- Choose your installation location (defaults to
C:\Program Files\EventListenersDemo) - Launch from:
- Start Menu β EventListenersDemo
- Desktop shortcut
C:\Program Files\EventListenersDemo\EventListenersDemo.exe
Linux (Debian/Ubuntu)
sudo apt install ./EventListenersDemo-linux.deb
# Launch from Applications menu or terminal:
EventListenersDemomacOS
- Download
EventListenersDemo-macos.dmg - Open the DMG file
- Drag EventListenersDemo to Applications
- Launch from Applications folder or Spotlight
If you prefer a portable option and already have Java 8 or newer installed:
- Download
EventListenersDemo-standalone.jarfrom Releases - Run with:
java -jar EventListenersDemo-standalone.jarNote for HiDPI Displays: If using Java 8 and text appears too small:
java -Dsun.java2d.uiScale=1.75 -Dflatlaf.uiScale=1.75 -jar EventListenersDemo-standalone.jar- Go to Actions tab
- Click the latest successful workflow run
- Download the artifact for your platform from:
installer-windowsinstaller-linuxinstaller-macosstandalone-jar
- Open the project folder in NetBeans.
- Build/Run using NetBeans (Run βΆ). NetBeans uses the provided
build.xmland project metadata. - NetBeans will produce a runnable JAR in
dist/(ignored by Git).
If you have Ant installed, you can use the NetBeans build script:
# From the project root (PowerShell)
ant clean jar
# Run the generated JAR
java -jar .\dist\javaGuiEventListenerDemo.jarNotes
- If you run the JAR with an older Java (e.g., 8) on HiDPI displays and see small UI text, you can either run with a newer JDK (17+) or pass a UI scale VM option, for example:
java -Dsun.java2d.uiScale=1.75 -Dflatlaf.uiScale=1.75 -jar .\dist\javaGuiEventListenerDemo.jarAdjust the scale value (1.25β2.0) to taste.
This reflects the actual folders in this repository. Items ignored by Git (per .gitignore) are marked with [ignored].
java-gui-event-listener-demo/
β
βββ build.xml # NetBeans/Ant build script
βββ LICENCE # CC BY-NC 4.0 license
βββ manifest.mf # JAR manifest
βββ README.md
β
βββ build/ [ignored] # Local build output (not tracked)
β βββ classes/
β
βββ lib/ # NetBeans libraries/config
β βββ nblibraries.properties
β βββ CopyLibs/
β
βββ nbproject/ # NetBeans project metadata
β βββ build-impl.xml
β βββ genfiles.properties
β βββ project.properties
β βββ project.xml
β βββ private/ [ignored]
β
βββ screenshots/ # Application screenshots
β βββ ...
β
βββ src/
β βββ javaGuiEventListenersDemo/
β βββ CompleteEventHandlersApp.java # Main application
β
βββ test/
From .gitignore, these are not tracked by Git and wonβt appear in commits:
- NetBeans private config:
nbproject/private/ - Build outputs:
/build/,/dist/,nbbuild/,nbdist/ - Compiled classes:
*.class - Logs/backups:
/logs/,*.log,*.bak,*~,*.swp - System files:
.DS_Store,Thumbs.db
| Technology | Purpose | Version |
|---|---|---|
| Java | Core programming language | 8+ |
| Swing | GUI framework | Built-in |
| AWT | Event handling framework | Built-in |
| FlatLaf | Modern look and feel theme | Latest |
| NetBeans + Ant | Build/run scripts | Provided |
- Automated Builds: GitHub Actions workflow creates installers for all platforms
- Runtime: Java 8+ compatible (standalone JAR)
- Installers: Bundled with JRE 21 for hassle-free installation
- CI/CD: Automatic releases on version tags
- Artifacts: Available via GitHub Releases and Actions
FlatLaf is a modern, flat design look and feel for Java Swing applications. It provides:
- β¨ Contemporary, professional appearance
- π¨ Better aesthetics than default Swing themes
- π± Consistency across different operating systems
- β‘ Excellent performance
-
Start with Basic Events Tab
- Click buttons, check boxes, move sliders
- Watch the event log to see which events fire
- Notice the method names and parameters
-
Explore Mouse & Key Events
- Move your mouse over the test area
- Click, drag, and use the mouse wheel
- Type in the text field to see keyboard events
-
Test Component Events
- Focus on different text fields
- Resize the window to see component events
- Add and remove components dynamically
-
Experiment with Window Events
- Create new test windows
- Minimize, maximize, and restore windows
- Switch between windows to see focus events
-
Try Advanced Features
- Expand/collapse tree nodes
- Edit table data
- Interact with menus and popups
- Monitor property changes
-
Work with Text Events
- Edit text areas to see document events
- Move the text caret
- Use undo/redo functionality
Event listeners follow the Observer pattern:
- A component (subject) maintains a list of listeners (observers)
- When an event occurs, the component notifies all registered listeners
- Each listener receives an event object with detailed information
Example:
button.addActionListener(e -> {
System.out.println("Button clicked!");
System.out.println("Command: " + e.getActionCommand());
});Adapter classes provide empty implementations of listener interfaces, allowing you to override only the methods you need:
// Instead of implementing all 5 MouseListener methods:
component.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// Only implement what you need
}
});Available Adapters:
MouseAdapter,KeyAdapter,FocusAdapterComponentAdapter,ContainerAdapterWindowAdapter,InternalFrameAdapterMouseMotionAdapter
We welcome contributions! This is an educational project designed to help others learn Java Swing.
-
Report Issues: Found a bug or have a suggestion?
- Open an issue on the Issues page
- Provide detailed information about the problem or enhancement
- Include steps to reproduce (for bugs)
-
Submit Improvements:
- Fork the repository
- Create a new branch (
git checkout -b feature/improvement) - Make your changes with clear comments
- Test thoroughly
- Submit a pull request with a detailed description
-
Enhance Documentation:
- Add more examples
- Improve explanations
- Create tutorials or guides
- Fix typos or clarify concepts
-
Give Solutions to opened issues
- Submit Improvements:
- Fork the repository
- Create a new branch (
git checkout -b feature/improvement) - Make your changes with clear comments
- Test thoroughly
- Submit a pull request with a detailed description and tagging the issue
- Keep code educational and well-commented
- Follow Java naming conventions
- Test all event handlers thoroughly
- Update documentation for new features
- Maintain the educational focus of the project
- Learn event-driven programming through hands-on interaction
- Understand the Observer pattern in a practical context
- Prepare for exams with comprehensive examples
- Complete assignments with working reference code
- Teaching tool for Java GUI programming courses
- Live demonstrations during lectures
- Assignment reference for students
- Lab exercises for hands-on learning
- Quick reference for event handler syntax
- Prototyping GUI applications
- Testing event handling logic
- Refresher on Swing event model
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.
- Share β copy and redistribute the material in any medium or format
- Adapt β remix, transform, and build upon the material
- Attribution β You must give appropriate credit, provide a link to the license, and indicate if changes were made
- NonCommercial β You may not use the material for commercial purposes
- β¨ Educational purposes in schools, universities, and online courses
- π Learning and teaching Java Swing programming
- π¬ Research and experimentation
- π€ Personal projects and portfolio development
- π Workshops and coding bootcamps (non-profit)
- β Selling this application or derivatives
- β Using in commercial training programs
- β Including in paid courses without permission
- β Commercial redistribution
When using or adapting this work, please credit as:
Java GUI Event Listener Learning Application
Original work by [Your Name/Organization]
https://github.com/yourusername/java-gui-event-listener-demo
Licensed under CC BY-NC 4.0
For commercial use inquiries, please open an issue or contact the repository owner.
- Oracle Java Documentation - Comprehensive Swing/AWT reference
- FlatLaf - Modern look and feel implementation
- Java Swing Community - Inspiration and best practices
- All Contributors - Thank you for helping improve this educational resource!
- Issues: Report bugs or request features
- Discussions: Ask questions or share ideas
- Email: [email protected] (for commercial inquiries)
- β Provide a complete reference for all Swing event handlers
- β Make event-driven programming easy to understand
- β Offer hands-on learning through interaction
- β Serve as a teaching aid for educators
- β Help developers quickly reference event handling
- β Maintain clear, educational code quality
- β Stay updated with Java best practices
- Add keyboard shortcut demonstrations
- Include drag-and-drop event handlers
- Add print event listeners
- Create video tutorials
- Develop interactive quizzes
- Add event filtering examples
- Include multi-threading event scenarios
- Create a web-based version using JavaFX
If you find this project helpful for learning Java Swing, please consider giving it a star! β
It helps others discover this educational resource and motivates continued development.
Made with β€οΈ for the Java learning community
- β Initial release
- β 30+ event listeners demonstrated
- β 70+ event handler methods
- β 6 categorized tabs
- β Real-time event logging
- β FlatLaf modern theme
- β Comprehensive documentation
- β Windows executable included
Last Updated: October 2025
Thanks for your interest in this project! π
We welcome pull requests for Hacktoberfest and beyond.
There are some simple issues already open that you can pick up β feel free to comment on one to let us know youβre working on it.
If you spot something else that could be improved or have a new idea, itβs totally fine to open a new issue and start a discussion before creating a PR.
- Fork this repository
- Create a new branch for your changes
- Make your changes (fix an issue or add something new)
- Open a Pull Request with a clear description of what you did
Weβll review all submissions and merge eligible PRs marked with the hacktoberfest-accepted label.
Even small improvements (like fixing typos, improving documentation, or cleaning up code) are welcome!
Happy contributing and happy Hacktoberfest! π±
[def]: ) page.



