-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouseCoords.java
More file actions
44 lines (35 loc) · 915 Bytes
/
MouseCoords.java
File metadata and controls
44 lines (35 loc) · 915 Bytes
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
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.*;
public class MouseCoords extends JFrame implements MouseMotionListener
{
ImageIcon map = new ImageIcon("Assets/Crater_Lake_Satellite_Map.jpg");
JLabel mapLabel = new JLabel(map);
public MouseCoords()
{
super("Mouse Coords");
setLayout(null);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(500,500);
setResizable(false);
add(mapLabel);
addMouseMotionListener(this);
setVisible(true);
}
public void mouseMoved(MouseEvent e)
{
mouseEventOutput("Mouse moved", e);
}
public void mouseDragged(MouseEvent e)
{
mouseEventOutput("Mouse dragged", e);
}
private void mouseEventOutput(String eventDescription, MouseEvent e)
{
System.out.println(eventDescription + ": " + e.getX() + ", " + e.getY());
}
public static void main(String[] args)
{
new MouseCoords();
}
}