-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouseMotionListenerEx2.java
More file actions
33 lines (30 loc) · 995 Bytes
/
MouseMotionListenerEx2.java
File metadata and controls
33 lines (30 loc) · 995 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
import java.awt.TextArea;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.JFrame;
import javax.swing.event.MouseInputListener;
public class MouseMotionListenerEx2 extends JFrame implements MouseMotionListener {
TextArea ta;
public MouseMotionListenerEx2(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setTitle("MouseMotionListener");
setLayout(null);
setSize(500,500);
ta = new TextArea();
ta.setBounds(100,100,300,500);
add(ta);
ta.addMouseMotionListener(this);
}
public void mouseDragged(MouseEvent m){
System.out.println("Mouse Dragged At "+m.getX()+","+m.getY());
ta.setText("Mouse Dragged At "+m.getX()+","+m.getY());
}
public void mouseMoved(MouseEvent m){
System.out.println("Mouse Moved At "+m.getX()+","+m.getY());
ta.setText("Mouse Moved At "+m.getX()+","+m.getY());
}
public static void main(String[] args) {
new MouseMotionListenerEx2();
}
}