This repository has been archived by the owner on Mar 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MouseManager.java
77 lines (58 loc) · 1.53 KB
/
MouseManager.java
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
74
75
76
77
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseListener;
public class MouseManager implements MouseListener, MouseMotionListener{
private boolean leftPressed, rightPressed;
private int mouseX, mouseY;
private UIManager uiManager;
public MouseManager(){
}
//getters
public void setUIManager(UIManager uiManager){
this.uiManager= uiManager;
}
public boolean isLeftPressed(){
return leftPressed;
}
public boolean isRightPressed(){
return rightPressed;
}
public int getMouseX(){
return mouseX;
}
public int getMouseY(){
return mouseY;
}
// implemented methods
public void mouseDragged(MouseEvent e){
}
public void mouseMoved(MouseEvent e){
mouseX = e.getX();
mouseY = e.getY();
if(uiManager != null){
uiManager.onMouseMove(e);
}
//System.out.println(mouseX + " " + mouseY);
}
public void mouseClicked(MouseEvent e){
}
public void mousePressed(MouseEvent e){
if(e.getButton() == MouseEvent.BUTTON1)
leftPressed = true;
if(e.getButton() == MouseEvent.BUTTON3)
rightPressed = true;
}
public void mouseReleased(MouseEvent e){
if(e.getButton() == MouseEvent.BUTTON1)
leftPressed = false;
if(e.getButton() == MouseEvent.BUTTON3)
rightPressed = false;
if(uiManager != null){
uiManager.onMouseRelease(e);
}
}
public void mouseEntered(MouseEvent e){
}
public void mouseExited(MouseEvent e){
}
}