How to use keyPressed & keyReleased Method of KeyListener in java applet?

Hello Friends, 

Today I will explain how can we write the keylistener program in java applet.
In this  program I used keyPressed & keyReleased methods of KeyListener.

   import java.applet.*;
import java.awt.*;
import java.awt.event.*;

/*


*/

public class fifth extends Applet implements KeyListener
{
String msg="";
public void init()
{
addKeyListener(this);
}
public void keyPressed(KeyEvent ke)
{
showStatus("Key Down");
}
public void keyReleased(KeyEvent ke)
{
showStatus("Key Up");
}
public void keyTyped(KeyEvent ke)
{
msg +=ke.getKeyChar();
repaint();
}
public void paint(Graphics g)
{
setBackground(Color.black);
setForeground(Color.blue);

g.setFont(new Font("Lucida Sans Typewriter",Font.BOLD,25));
g.drawString(msg,20,50);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *