Description: The java.awt.event.MouseEvent class is a part of the Java AWT (Abstract Window Toolkit) package and provides event-driven interaction with the mouse. It contains a variety of methods that allow developers to retrieve information about mouse events, such as the position of the mouse, the button pressed, and the time at which the event occurred. The getWhen() method is used to retrieve the time at which the event occurred.
Code Examples: Here are a few examples that demonstrate how to use the getWhen() method:
Example 1: This example creates a mouse listener that prints the time at which a mouse click occurred.
import java.awt.event.*; import javax.swing.*;
public class MouseListenerExample implements MouseListener { public void mouseClicked(MouseEvent event) { System.out.println("Mouse clicked at: " + event.getWhen()); } // Other methods of MouseListener interface }
Example 2: This example creates a mouse motion listener that prints the current time when the mouse is moved.
import java.awt.event.*; import javax.swing.*;
public class MouseMotionListenerExample implements MouseMotionListener { public void mouseMoved(MouseEvent event) { System.out.println("Mouse moved at: " + event.getWhen()); } // Other methods of MouseMotionListener interface }
Package Library: The java.awt.event.MouseEvent class is a part of the java.awt.event package in the Java AWT (Abstract Window Toolkit) library. This package provides classes and interfaces for creating and handling events in GUI components.
Java MouseEvent.getWhen - 30 examples found. These are the top rated real world Java examples of java.awt.Event.MouseEvent.getWhen extracted from open source projects. You can rate examples to help us improve the quality of examples.