forked from ranjansharma255/Java_Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyDemo.java
More file actions
40 lines (39 loc) · 829 Bytes
/
KeyDemo.java
File metadata and controls
40 lines (39 loc) · 829 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
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/* <applet code= KeyDemo width = 300 height = 300></applet>*/
public class KeyDemo extends Applet implements KeyListener
{
String msg = " ";
int x = 30, y = 30;
public void init()
{
addKeyListener(this);
requestFocus(true);
}
public void paint(Graphics g)
{
g.drawString(msg,x,y);
}
public void keyPressed(KeyEvent e)
{
showStatus("key Pressed");
repaint();
}
public void keyReleased(KeyEvent e)
{
showStatus("key Released");
repaint();
}
public void keyTyped(KeyEvent e)
{
char ch = e.getKeyChar();
if(ch == 'M' || ch == 'm')
msg = "Good morning";
else if(ch == 'E' || ch == 'e')
msg = "Good Evening";
else if(ch == 'A' || ch == 'a')
msg = "Good Afternoon";
repaint();
}
}