source code name: KeyDemo1.java
import java.awt.*;
import java.awt.event.*;
class KeyDemo1 extends Frame implements KeyListener
{
public KeyDemo1()
{
addKeyListener(this);
}
public void keyPressed(KeyEvent me)
{
System.out.println("key is Pressed");
}
public void keyReleased(KeyEvent me){
System.out.println("key is Released");
}
public void keyTyped(KeyEvent me){
System.out.println("key is Typed");
}
public static void main(String[] args)
{
KeyDemo1 f=new KeyDemo1();
f.setTitle("Key Event program");
f.setSize(400,500);
f.setVisible(true);
}
}
output:
0 Comments
Post a Comment