/* * This class shows what happens when you use click on * mouse buttons. Look at the console to see messages * corresponding to the events triggered by the mouse. * By the way, try to get out of the area defined by the * window and you will see how an appropriate message is * generated. * */ /* Required because we are dealing with events */ import java.awt.event.*; /* * The MouseListener interface defines the methods * that are associated with mouse actions. The * MouseHandler is the class where you will define * what should take place when a mouse event is * recognized. */ public class MouseHandler implements MouseListener { /* * Invoked when the mouse button has been clicked * (pressed and released) on a component. */ public void mouseClicked(MouseEvent e){ // No activity for now } /* Invoked when the mouse enters a component.*/ public void mouseEntered(MouseEvent e){ System.out.println("Mouse Entered"); } /* Invoked when the mouse exits a component. */ public void mouseExited(MouseEvent e){ System.out.println("Mouse Exited"); } /* Invoked when a mouse button has been pressed on a component.*/ public void mousePressed(MouseEvent e){ System.out.print("Mouse Pressed at coordinates: "); System.out.println("(" + e.getX() + "," + e.getY() + ")"); } /* Invoked when a mouse button has been released on a component. */ public void mouseReleased(MouseEvent e){ System.out.println("Mouse Released"); } }