-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGM.java
96 lines (75 loc) · 1.84 KB
/
GM.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
88
89
90
91
92
93
94
95
96
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.*;
public class GM extends JFrame{
private BoardPanel panel;
private Mouse m;
/**
* Launch the application.
*/
public GM() {
panel=new BoardPanel();
m=new Mouse();
this.setContentPane(panel);
panel.addMouseListener(m);
this.setVisible(true);
this.setSize(500, 500);
this.setTitle("Test");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class BoardPanel extends JPanel{
private static final int rows=3;
private static final int columns=3;
int xcrood;
int ycrood;
public void setXcrood(int w) {
xcrood=w;
}
public void setYcrood(int r) {
ycrood=r;
}
public void paintComponent(Graphics g) {
int x=this.getHeight()/rows;
int y=this.getWidth()/columns;
for(int i=0;i<rows;i++) {
for(int j=0;j<columns;j++) {
int a=i*x;
int b=j*y;
g.drawRect(a, b, x, y);
}
}
g.setColor(Color.green);
g.fillOval(xcrood, ycrood, 50, 50);
panel.repaint(100, 100, 100, 100);
}
}
class Mouse implements MouseListener{
@Override
public void mouseClicked(MouseEvent e) {
int x=e.getX();
int y=e.getY();
panel.setXcrood(x);
panel.setYcrood(y);
panel.repaint();
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
}
}