-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDrawingUsingMouse.java
More file actions
42 lines (36 loc) · 906 Bytes
/
DrawingUsingMouse.java
File metadata and controls
42 lines (36 loc) · 906 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
package Testing;
import javax.swing.*;
import java.awt.*;
import java.awt.Graphics;
import java.awt.event.*;
public class DrawingUsingMouse extends JFrame implements MouseMotionListener{
Label l;
int x,y;
DrawingUsingMouse(){
l = new Label() ;
setVisible(true);
setBounds(200,200,400,400);
setTitle("JOHNS");
l.setBounds(10,0,150,10);
setLayout(null);
l.setText("X axis : Y axis : ");
add(l);
addMouseMotionListener(this);
}
public void mouseDragged(MouseEvent e) {
x=e.getX();
y=e.getY();
l.setText("X-axis : "+e.getX() +" Y-axis : "+e.getY());
repaint();
}
public void mouseMoved(MouseEvent e) {
l.setText("X-axis : "+e.getX() +" Y-axis : "+e.getY());
}
public void paint(Graphics g) {
g.setColor(Color.RED);
g.fillOval(x,y,5,5);
}
public static void main(String[] args) {
new DrawingUsingMouse();
}
}