-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyMouseListener.java
More file actions
40 lines (30 loc) · 1.05 KB
/
MyMouseListener.java
File metadata and controls
40 lines (30 loc) · 1.05 KB
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
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
public class MyMouseListener implements MouseListener, MouseMotionListener {
private final App app;
public MyMouseListener(App app) {
this.app = app;
}
@Override
public void mouseClicked(MouseEvent e) {}
@Override
public void mousePressed(MouseEvent e) {
App.getGrains().add(new Sand((e.getX() / Constants.SIZE) * Constants.SIZE, (e.getY() / Constants.SIZE) * Constants.SIZE));
app.addMouseMotionListener(this);
}
@Override
public void mouseReleased(MouseEvent e) {
app.removeMouseMotionListener(this);
}
@Override
public void mouseEntered(MouseEvent e) {}
@Override
public void mouseExited(MouseEvent e) {}
@Override
public void mouseDragged(MouseEvent e) {
App.getGrains().add(new Sand((e.getX() / Constants.SIZE) * Constants.SIZE, (e.getY() / Constants.SIZE) * Constants.SIZE));
}
@Override
public void mouseMoved(MouseEvent e) {}
}