-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAllHandlers.java
More file actions
273 lines (210 loc) · 6.36 KB
/
AllHandlers.java
File metadata and controls
273 lines (210 loc) · 6.36 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
//Parth Upadhyay
//3/11/22
//AllHandlers.java
//To print out all handlers and see their functions, the words go red once the function is done
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Scanner;
public class AllHandlers
{
int choice = 0;
JFrame frame;
DrawingPanel canvas;
public static void main (String[] args)
{
AllHandlers kt = new AllHandlers();
kt.run2();
} // end main
public void run2()
{
frame = new JFrame("AllHandlers.java");
DrawingPanel panel = new DrawingPanel();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize( 600, 600);
frame.setLocation(400,50);
frame.setResizable(true);
frame.getContentPane().add(panel, BorderLayout.CENTER);
frame.addMouseListener(panel);
frame.addMouseMotionListener(panel);
frame.setVisible(true);
}
}
class DrawingPanel extends JPanel implements KeyListener, MouseListener, MouseMotionListener {
private int triX, triY;
private Timer trimover;
private boolean [] check = {false, false, false, false, false, false, false, false, false, false, false, false,false};
boolean reset = false;
//boolean control = false;
/*
boolean enter = false;
boolean exit = false;
boolean move = false;
boolean drag = false;
boolean click = false;
boolean press = false;
boolean release = false;
boolean letter = false;
boolean number = false;
boolean character = false;
boolean keycode = false;
*/
public DrawingPanel() {
triX = 0;
triY = 0;
addKeyListener(this);
// create timer for animation of ball
TriMover tritimer = new TriMover();
trimover = new Timer(5, tritimer);
trimover.start();
}
class TriMover implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (check[12] == false)
{
triX++;
if (triX > 600)
triX = 40;
}
else
{
triX--;
if (triX < 0)
triX = 550;
}
repaint();
grabFocus();
}
// end BallMover
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
setBackground(Color.WHITE);
g.setColor(Color.BLACK);
g.setFont(new Font("Serif", Font.PLAIN, 20));
//titles
g.drawString("Mouse", 100, 80);
g.drawString("Keyboard", 100, 230);
g.setFont(new Font("Serif", Font.PLAIN, 18));
//others
g.drawRect(100, 100, 100, 25);
g.drawRect(200, 100, 100, 25);
g.drawRect(300, 100, 100, 25);
g.drawRect(400, 100, 100, 25);
g.drawRect(100, 150, 100, 25);
g.drawRect(200, 150, 100, 25);
g.drawRect(300, 150, 100, 25);
g.drawRect(100, 250, 100, 25);
g.drawRect(200, 250, 100, 25);
g.drawRect(300, 250, 100, 25);
g.drawRect(400, 250, 100, 25);
String[] str = {"Moved", "Dragged", "Entered", "Exited", "Clicked", "Pressed", "Released", "Letter", "Number", "Character", "KeyCode"};
int[] arrx = {125, 225, 325, 425, 125, 225, 325, 125, 225, 325, 425};
int[] arry = {120, 120, 120, 120, 170, 170, 170, 270, 270, 270, 270};
if ( reset == true)
{
for (int i = 0; i < 11; i ++)
{
check[i] = false;
g.setColor(Color.BLACK);
g.drawString(str[i], arrx[i], arry[i]);
}
reset = false;
}
for (int i = 0; i < 11; i ++)
{
if (check[i])
g.setColor(Color.RED);
g.drawString(str[i], arrx[i], arry[i]);
g.setColor(Color.BLACK);
}
int [] arrx2 = {50, 0, 100};
int [] arry2 = {500, 550, 550};
g.setColor(Color.YELLOW);
for (int i = 0; i < 3; i ++)
{
arrx2[i] += triX;
arry2[i] += triY;
}
g.fillPolygon(arrx2, arry2, 3);
} // end paintComponent
public void keyTyped(KeyEvent e) {}
public void keyPressed(KeyEvent e)
{
char c = e.getKeyChar();
switch (c)
{
case 'r':
reset = true;
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
check[7] = true;
check[9] = true;
check[10] = true;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
check[8] = true;
check[9] = true;
check[10] = true;
break;
}
switch(c)
{
case KeyEvent.VK_CONTROL:
check[12] = false;
check[10] = true;
break;
case KeyEvent.VK_UP:
case KeyEvent.VK_DOWN:
case KeyEvent.VK_LEFT:
case KeyEvent.VK_RIGHT:
case KeyEvent.VK_SHIFT:
case KeyEvent.VK_TAB:
case KeyEvent.VK_DELETE:
check[10] = true;
break;
}
repaint();
}
public void keyReleased(KeyEvent e) {}
public void mousePressed (MouseEvent e) {check[5] = true; repaint();}
public void mouseReleased (MouseEvent e) {check[6] = true; repaint();}
public void mouseClicked (MouseEvent e) {check[4] = true; repaint();}
public void mouseEntered (MouseEvent e) {check[2] = true; repaint();}
public void mouseExited (MouseEvent e) {check[3] = true; repaint();}
public void mouseMoved (MouseEvent e) {check[0] = true; repaint();}
public void mouseDragged (MouseEvent e) {check[1] = true; repaint();}
}