0% found this document useful (0 votes)
5 views5 pages

Practical No 10

Uploaded by

fdj5045
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Practical No 10

Uploaded by

fdj5045
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Practical No 10

Batch- t2

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code=KEx1.class height=300 width=300>
</applet>*/
public class KEx1 extends Applet implements KeyListener
{
public void init()
{
addKeyListener(this);
}
public void keyReleased(KeyEvent ke)
{
}
public void keyPressed(KeyEvent ke)
{
showStatus("Key Pressed");
repaint();
}
public void keyTyped(KeyEvent ke)
{
}

Output:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code="SKDemo" height=300
width=300>
</applet>*/
public class SKDemo extends Applet
implements KeyListener
{
String msg = "";
public void init()
{
addKeyListener(this);
}
public void keyPressed(KeyEvent e)
{
int key = e.getKeyCode();
switch(key)
{
case KeyEvent.VK_F1:
msg = msg+"F1";
break;
case KeyEvent.VK_F2:
msg = msg+"F2";
break;
case KeyEvent.VK_F3:
msg = msg+"F3";
break;
case KeyEvent.VK_F4:
msg = msg+"F4";
break;
case KeyEvent.VK_RIGHT:
msg = msg+"RIGHT";
break;
case KeyEvent.VK_LEFT:
msg = msg+"LEFT";
break;
case KeyEvent.VK_UP:
msg = msg+"UP";
break;
case KeyEvent.VK_DOWN:
msg = msg+"DOWN";
break;
}
repaint();
}
public void keyReleased(KeyEvent e)
{
}
public void keyTyped(KeyEvent e)
{
}
public void paint(Graphics g)
{
g.drawString(msg, 10, 10);
}

Output:

You might also like