MCA 8th Lab Program choose any one
/* Java Program to demonstrate the event actions associated with a keyboard */
import [Link].*;
import [Link].*;
import [Link].*;
class Keyboard_Event implements KeyListener,ActionListener
{
static JFrame frame;
static JTextField output;
static JTextField input;
//Driver function
public static void main(String args[])
{
//Create a frame
frame=new JFrame("Keyboard Event");
[Link]([Link]);
[Link](500,500);
[Link](null);
//Create a text field for output
output=new JTextField();
[Link](0,0,500,50);
[Link](output);
//Create a text field for input
input=new JTextField();
[Link](0,400,500,50);
[Link](input);
//Create an exit button
JButton exit=new JButton("Exit");
[Link](220,200,60,30);
[Link](exit);
//Create an object of the class
Keyboard_Event obj=new Keyboard_Event();
//Associate KeyListener with input
[Link](obj);
//Associate ActionListener with exit
[Link](obj);
[Link](true);
}
//function to dispose the frame when exit button is clicked
@Override
public void actionPerformed(ActionEvent e)
{
[Link]();
}
/*function to display the unicode of key released
and the character if it is a letter or a digit*/
@Override
public void keyReleased(KeyEvent e)
{
[Link]("");
[Link]("Key Released : "+[Link]());
if([Link]([Link]()))
keyTyped(e);
if([Link]([Link]()))
keyTyped(e);
}
/*function to display the unicode of key pressed
and the character if it is a letter or a digit*/
@Override
public void keyPressed(KeyEvent e)
{
[Link]("");
[Link]("Key Pressed : "+[Link]());
if([Link]([Link]()))
keyTyped(e);
if([Link]([Link]()))
keyTyped(e);
}
//function to display the character of the key typed
@Override
public void keyTyped(KeyEvent e)
{
[Link]("");
[Link]("Key Typed : "+[Link]());
}
}
Reference: Java Program to Handle KeyBoardEvent - Sanfoundry