-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion70.java
More file actions
58 lines (55 loc) · 1.35 KB
/
Question70.java
File metadata and controls
58 lines (55 loc) · 1.35 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
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/* program to create an applet to handle keyboard events
(message for F1, F2, F3, F4, F5 to be displayed) */
/* <applet code="Question70" height="100" width="300">
</applet>
*/
public class Question70 extends Applet implements KeyListener {
String msg = "";
int X = 10, Y = 20;
public void init () {
addKeyListener (this);
requestFocus ();
}
public void keyPressed (KeyEvent ke) {
showStatus ("Key Down!");
int key = ke.getKeyCode ();
switch (key) {
case KeyEvent.VK_F1: msg += "<F1>";
break;
case KeyEvent.VK_F2: msg += "<F2>";
break;
case KeyEvent.VK_F3: msg += "<F3>";
break;
case KeyEvent.VK_F4: msg += "<F4>";
break;
case KeyEvent.VK_F5: msg += "<F5>";
break;
case KeyEvent.VK_UP: msg += "<Up Arrow>";
break;
case KeyEvent.VK_DOWN: msg += "<Down Arrow>";
break;
case KeyEvent.VK_LEFT: msg += "<Left Arrow>";
break;
case KeyEvent.VK_RIGHT: msg += "<Right Arrow>";
break;
case KeyEvent.VK_PAGE_UP: msg += "<PgUp>";
break;
case KeyEvent.VK_PAGE_DOWN: msg += "<PgDn>";
break;
}
repaint ();
}
public void keyReleased (KeyEvent ke) {
showStatus ("Key up!");
}
public void keyTyped (KeyEvent ke) {
msg += ke.getKeyChar ();
repaint ();
}
public void paint (Graphics g) {
g.drawString (msg, X, Y);
}
}