-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuser.java
More file actions
151 lines (140 loc) · 3.8 KB
/
user.java
File metadata and controls
151 lines (140 loc) · 3.8 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package fungrid;
import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseAdapter;
import javax.swing.JOptionPane;
import javax.swing.JButton;
class user extends ButtonGrid implements Runnable,MouseListener {
//public Thread t;
boolean isRunning;
float xpos,ypos;
int x,y;
boolean mouseEntered;
int score;
public user(int w,int l)
{
super(w,l);
score=0;
xpos=0;
ypos=0;
isRunning=true;
for(int i=0;i<l;i++)
for(int j=0;j<w;j++)
{
grid[i][j].addMouseListener(new MouseAdapter()
{ @Override
public void mouseClicked(MouseEvent e)
{
JButton source=(JButton)e.getSource();
xpos=e.getXOnScreen();
ypos=e.getYOnScreen();
System.out.println(xpos+ypos+"yeqaaaahhh");
// Save the coordinates of the click lke this.
//System.out.println("yeqaaaahhh");
//JOptionPane.showMessageDialog(null, "x:"+xpos+"y:"+ypos);
// Check if the click was inside the rectangle area.
x=(int)xpos/50;
y=(int)ypos/50;
System.out.println("score");
Color col=grid[x][y].getBackground();
System.out.println(grid[x][y].getBackground());
Color s=new Color(0xFF3333);
if(grid[x][y].getBackground()==s)
{score++;
System.out.println(score);
}
}});
// JOptionPane.showMessageDialog(null,"in user!!");
}}//}//}
@Override
public void run(){
//code here
try{while(isRunning){
if(mouseEntered)
increment();
//hello();
//System.out.println("ur score"+score);
}
}
catch(Exception e)
{
// e.printStackTrace();
System.out.println("error");
}
}
void hello()
{
JOptionPane.showMessageDialog(null,"in user!!");
}
public void kill()
{
isRunning=false;
}
void increment()
{
//xpos=me.getX();
//ypos=me.getY();
System.out.println(xpos+ypos+"yeqaaaahhh");
x=(int)xpos/10;
y=(int)ypos/10;
Color s=new Color(0xFF3333);
if(grid[x][y].getBackground()==s)
{score++;
System.out.println(score);
}}
//void setx(float x)
//{
// xpos=x;
//}
//void sety(float y)
//{
// ypos=y;
//}
@Override
public void mouseClicked (MouseEvent me) {
//JButton source=(JButton)me.getSource();
//setx(me.getX());
//sety(me.getY());
xpos=me.getXOnScreen();
ypos=me.getYOnScreen();
System.out.println(xpos+ypos+"yeqaaaahhh");
// Save the coordinates of the click lke this.
//System.out.println("yeqaaaahhh");
//JOptionPane.showMessageDialog(null, "x:"+xpos+"y:"+ypos);
// Check if the click was inside the rectangle area.
x=(int)xpos/50;
y=(int)ypos/50;
System.out.println("score");
Color col=grid[x][y].getBackground();
System.out.println(grid[x][y].getBackground());
Color s=new Color(0xFF3333);
if(grid[x][y].getBackground()==s)
{score++;
System.out.println(score);
}}
@Override
public void mousePressed(MouseEvent me) {
xpos=me.getX();
ypos=me.getY();
// Save the coordinates of the click lke this.
System.out.println("yeqaaaahhh");
}
@Override
public void mouseReleased(MouseEvent me) {
}
@Override
public void mouseEntered(MouseEvent me) {
mouseEntered=true;
//JOptionPane.showMessageDialog(null, "yeahx:"+xpos+"y:"+ypos);
System.out.println("ENterde");
}
@Override
public void mouseExited(MouseEvent me) {
mouseEntered=false;
}
public user getScore()
{
return this;
}
}