-
Notifications
You must be signed in to change notification settings - Fork 0
/
MouseTracker
73 lines (62 loc) · 2.17 KB
/
MouseTracker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package main;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
*
* @author nicob
*/
public class MouseTracker extends JFrame implements MouseListener, MouseMotionListener {
JLabel mousePosition;
@Override
public void mouseClicked(MouseEvent me) {
mousePosition.setText("Mouse clicked at coordinate : ["+me.getX()+","+me.getY()+"]");
}
@Override
public void mousePressed(MouseEvent me) {
mousePosition.setText("Mouse pressed at coordinates : ["+me.getX()+","+me.getY()+"]");
}
@Override
public void mouseReleased(MouseEvent me) {
mousePosition.setText("Current mouse coordinates : ["+me.getX()+","+me.getY()+"]");
}
@Override
public void mouseEntered(MouseEvent me) {
mousePosition.setText("Current mouse Coordinates : ["+me.getX()+","+me.getY()+"]");
}
@Override
public void mouseExited(MouseEvent me) {
mousePosition.setText("Mouse outside access window");
}
@Override
public void mouseDragged(MouseEvent me) {
mousePosition.setText("Mouse dragged at coordinates : ["+me.getX()+","+me.getY()+"]");
}
@Override
public void mouseMoved(MouseEvent me) {
mousePosition.setText("Mouse moved to coordinates : ["+me.getX()+","+me.getY()+"]");
}
void start() {
mousePosition=new JLabel();
addMouseListener( this ); // listens for own mouse and
addMouseMotionListener( this ); // mouse-motion events
setLayout(new FlowLayout(1));
add(mousePosition);
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
setSize(size );
setUndecorated(true);
setVisible( true );
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
//http://mrbool.com/creating-a-simple-mouse-analyzer-with-java-swing/24507