-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainCanvas.java
More file actions
68 lines (54 loc) · 1.65 KB
/
MainCanvas.java
File metadata and controls
68 lines (54 loc) · 1.65 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
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
package mandeljava;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import javax.swing.event.MouseInputListener;
class MainCanvas extends Canvas implements MouseInputListener {
private int centerClickX;
private int centerClickY;
private int radius;
MainCanvas(){
addMouseListener(this);
addMouseMotionListener(this);
}
@Override
public void paint(Graphics g) {
g.drawImage(Main.I, 0, 0, Color.red, null);
}
@Override
public void mouseClicked(MouseEvent e) {
Graphics g = this.getGraphics();
g.drawImage(Main.I, 0, 0, Color.red, null);
g.setColor(Color.red);
g.drawRect(this.centerClickX - this.radius, this.centerClickY - this.radius, this.radius * 2, this.radius * 2);
}
@Override
public void mousePressed(MouseEvent e) {
this.centerClickX = e.getX();
this.centerClickY = e.getY();
}
@Override
public void mouseReleased(MouseEvent e) {
Main.updateInputs(this.centerClickX, this.centerClickY, this.radius);
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseDragged(MouseEvent e) {
int xDist = e.getX() - this.centerClickX;
int yDist = e.getY() - this.centerClickY;
this.radius = (int) Math.abs(Math.round(Math.hypot(xDist, yDist)));
Graphics g = this.getGraphics();
g.drawImage(Main.I, 0, 0, Color.red, null);
g.setColor(Color.red);
g.drawRect(this.centerClickX - this.radius, this.centerClickY - this.radius, this.radius * 2, this.radius * 2);
}
@Override
public void mouseMoved(MouseEvent e) {
}
}