StudyLover
  • Home
  • Study Zone
  • Features
    • Workout Interval Timer
    • Typing Tutor
  • Profiles
  • Contact us
  • Sign in
StudyLover The Interaction Tracker
Download
  1. Java
  2. Programs
The Event Responder : The ArrayList Manager
Programs
Initiative: To monitor detailed user inputs like mouse movements and keystrokes using Adapter classes.
import javax.swing.*; // Import Swing
import java.awt.event.*; // Import event listeners and adapters

public class InteractionTracker { // Define class for advanced input tracking
    public static void main(String[] args) { // Main entry point
        JFrame f = new JFrame("Input Interaction Tracker"); // Create the window frame
        f.setSize(400, 300); // Set frame size
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Handle exit
        
        JLabel mouseInfo = new JLabel("Mouse: Moving..."); // Label for mouse data
        JLabel keyInfo = new JLabel("Keyboard: Press a key..."); // Label for keyboard data
        f.setLayout(new java.awt.FlowLayout()); // Set layout manager
        f.add(mouseInfo); // Add mouse label
        f.add(keyInfo); // Add key label
        
        // Tracking mouse clicks with an Adapter (only override what you need)
        f.addMouseListener(new MouseAdapter() { // Use MouseAdapter to simplify code
            @Override // Override the clicked event
            public void mouseClicked(MouseEvent e) { // Run on mouse click
                mouseInfo.setText("Clicked at: [" + e.getX() + ", " + e.getY() + "]"); // Update label with X,Y
                System.out.println("Mouse Clicked at Coordinates: " + e.getPoint()); // Log to console
            } // End of click logic
        }); // End of mouse adapter
        
        // Tracking keyboard input (Frame must be focusable)
        f.setFocusable(true); // Ensure frame can capture keys
        f.addKeyListener(new KeyAdapter() { // Use KeyAdapter to simplify code
            @Override // Override the key typed event
            public void keyTyped(KeyEvent e) { // Run when key is pressed/typed
                keyInfo.setText("Last Key Typed: '" + e.getKeyChar() + "'"); // Show the character typed
                System.out.println("Key Typed: " + e.getKeyChar()); // Log key to console
            } // End of key logic
        }); // End of key adapter
        
        f.setLocationRelativeTo(null); // Center window
        f.setVisible(true); // Display UI
        
        System.out.println("Interaction Lab: Mouse and Key tracking enabled."); // Final log
    } // End of main method
} // End of InteractionTracker class
The Event Responder The ArrayList Manager
Our Products & Services
  • Home
Connect with us
  • Contact us
  • info.studylover@gmail.com

StudyLover - About us

The Best knowledge for Best people.

Copyright © StudyLover
Powered by Odoo - Create a free website