-
Notifications
You must be signed in to change notification settings - Fork 0
/
FrameDragListener.java
87 lines (59 loc) · 2.01 KB
/
FrameDragListener.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
78
79
80
81
82
83
84
85
86
87
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Desktop;
import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.net.URI;
/*
-- Desktop Watch V1.0 --
Created By _ Vijay Mahajan.
Designed By _ Vijay Mahajan.
-----------------------------------------------------------------
Follow Me On GitHub:- ("https://github.com/crazyindiandeveloper")
Subscribe My YouTube Channel:- ("https://bit.ly/3dNveY3")
Published On " 6.7.2021 "
*/
public class FrameDragListener extends MouseAdapter {
private final JFrame frame;
private Point mouseDownCompCoords =null;
static int i=0;
public FrameDragListener(JFrame frame) {
this.frame = frame;
}
public void mouseReleased(MouseEvent e) {
mouseDownCompCoords = null;
}
public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
i=1;
} else if (e.getButton() == MouseEvent.BUTTON2) {
i=2;
} else if (e.getButton() == MouseEvent.BUTTON3) {
i=3;
}
if(i==1){
mouseDownCompCoords = e.getPoint();
i=0;
}else if(i==2){
try {
URI uri= new URI("http://www.github.com/crazyindiandeveloper");
java.awt.Desktop.getDesktop().browse(uri);
}
catch (Exception EX) {
EX.printStackTrace();
}
}
}
public void mouseDragged(MouseEvent e) {
Point currCoords = e.getLocationOnScreen();
try {
frame.setLocation(currCoords.x - mouseDownCompCoords.x, currCoords.y - mouseDownCompCoords.y);
}
catch(Exception unfix){unfix.printStackTrace();}
}
}