BCA

AJAVA LAB

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6

PART B

PROGRAM 7 PROGRAM 8 PROGRAM 9 PROGRAM 10 PROGRAM 11 PROGRAM 12 PROGRAM 13 PROGRAM 14 PROGRAM 15 . . .

OUTPUT:
 
 
 Write a program to implement keyboard events
/ *<applet code="keyevent" width=300 height=100> </ applet>*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class keyevent extends Applet implements KeyListener
{
final Font fnt=new Font("Verdana",Font.PLAIN,15);
String msg="KeyEvents ->";
public void init( )
{
addKeyListener(this);
requestFocus();
}
public void paint(Graphics g)
{
g.setFont(fnt);
g.drawString(msg,20 ,30 );
}
public void keyPressed(KeyEvent k)
{
showStatus("KEY PRESSED");
int key=k.getKeyCode();
msg="PRESSED KEY IS: ";
switch(key)
{
case KeyEvent.VK_UP:
msg+="MOVE TO UP";
break;
case KeyEvent.VK_DOWN:
msg+="MOVE TO DOWN";
break;
case KeyEvent.VK_LEFT:
msg+="MOVE TO LEFT";
break;case KeyEvent.VK_RIGHT:
msg+="MOVE TO RIGHT";
break;
}
repaint();
}
public void keyReleased(KeyEvent k)
{
showStatus("KEY RELEASED");
}
public void keyTyped(KeyEvent k)
{
showStatus("KEY TYPED");
msg="YOU TYPED :";
msg+=k.getKeyChar();
repaint();
}
}