import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class keytest extends Applet implements KeyListener
{
int xa[] = { 120, 125, 150, 150, 200, 200 };
int ya[] = { 175, 100, 100, 175, 175, 200 };
Graphics g;
public void init()
{
g=getGraphics();
addKeyListener(this);
}
public void paint(Graphics g)
{
g.drawString("Enter any Character in the keyboard....",20,20);
}
public void keyPressed(KeyEvent e)
{
g.drawPolygon(xa, ya, 6);
showStatus("key pressed");
}
public void keyReleased(KeyEvent e)
{ showStatus("key released - You have Realsed the Key"); }
public void keyTyped(KeyEvent e)
{ showStatus("key typed : "+e.getKeyChar()); }
}
/* <applet code ="keytest.class" width = 350 height =350>
</applet> */Java
Java Applet - Display the Polygon when the user presses the Keyboard.

Written by
View ProfileSenthilvelan Sambamoorthy
Senthilvelan Sambamoorthy is working as a Professor in Department of Master of Computer Applications, Paavai Engineering College, Namakkal, Tamilnadu, India, He is Masters in Computers Applications. Having 18+ years of experience and his area of interest is Java, JSP, Servlet, J2EE, C#, PHP, Python ASP.NET, SQL Server and etc.
