-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathPaintLine.java
More file actions
49 lines (41 loc) · 1.62 KB
/
PaintLine.java
File metadata and controls
49 lines (41 loc) · 1.62 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
/*
* File: PaintLine.java
* ----------------------------
* Paint-ის მონაკვეთის ხატვის გაკეთება, ჯერ აჭერ მაუსს, ფიქსირდება ერთი წვერო, მერე
* მაუსის მოძრაობისას მონაკვეთიც მოძრაობს რადგან მეორე წვერო არაა დაფიქსირებული და
* კლიკით ფიქსირდება მეორე წვეროც.
*/
import acm.graphics.*;
import acm.program.*;
import java.awt.event.*;
public class PaintLine extends GraphicsProgram {
private boolean startClicked;
private boolean endClicked;
private GLine line;
//in the start there are no points clicked.
//adding mouse listeners.
public void init() {
startClicked = false;
endClicked = false;
addMouseListeners();
}
//if starting point isn't clicked yet and user clicked it now,
//add add line on those coordinates.
//else if end point isn't clicked yet and user clicked it,
//mark its boolean as true.
public void mouseClicked(MouseEvent e) {
if (!startClicked) {
line = new GLine(e.getX(), e.getY(), e.getX(), e.getY());
add(line);
startClicked = true;
} else if (!endClicked) {
endClicked = true;
}
}
//if starting point has already set, update line ending point
//to show that line ending point is moving with cursor.
public void mouseMoved(MouseEvent e) {
if (startClicked && !endClicked)
line.setEndPoint(e.getX(), e.getY());
}
}