/* Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
This code is for educational purposes only. Use at own risk.*/

1. public class MouseCoords 

2.     extends java.applet.Applet 

3.     implements java.awt.event.MouseListener 

4.

5.   String strpaint = "No click as yet"

6.  

7.   public MouseCoords () 

8.   { 

9.     addMouseListener ( this ) ; 

10.  

11.     setBackground ( java.awt.Color.orange ) ; 

12.   } 

13.  

14.   public void paint ( java.awt.Graphics  gr ) 

15.   { 

16.     gr.drawString ( strpaint , 10 , 20 ); 

17.   } 

18.  

19.   public void mouseClicked 

20.    ( java.awt.event.MouseEvent  ev  ) 

21.   { 

22.     int x ,y ; 

23.      

24.     x = ev.getX() ;     

25.     y = ev.getY() ;     

26.  

27.     strpaint = " x = "   +  x  +   " , y = "   +  y  ; 

28.     repaint (); 

29.   } 

30.    

31.   public void mousePressed(java.awt.event.MouseEvent ev) { } 

32.   public void mouseReleased(java.awt.event.MouseEvent ev) { } 

33.   public void mouseEntered(java.awt.event.MouseEvent ev) { } 

34.   public void mouseExited(java.awt.event.MouseEvent ev) { } 

35.