0% found this document useful (0 votes)
18 views2 pages

PracticalNo10 1

This document describes a Java program that demonstrates the status of key events in an Applet window, including KeyPressed, KeyReleased, and KeyTyped. The program uses a KeyListener to update a label with the name of the key pressed or released. The main class creates a frame with a text area to capture key events and display their status.

Uploaded by

Ashish Mavani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

PracticalNo10 1

This document describes a Java program that demonstrates the status of key events in an Applet window, including KeyPressed, KeyReleased, and KeyTyped. The program uses a KeyListener to update a label with the name of the key pressed or released. The main class creates a frame with a text area to capture key events and display their status.

Uploaded by

Ashish Mavani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Practical No.

: 10

Practical Name: Write a program to demonstrate status of key on Applet window such as
KeyPressed, KeyReleased, KeyUp, KeyDown.

Roll No.: 47

Student Name: Mavani Ashish Shantilal

Program:
import java.awt.*;
import java.awt.event.*;

class practical10_1 extends Frame implements KeyListener


{
Label l1;
TextArea t1;
practical10_1()
{
setTitle("KeyListener");
setVisible(true);
setSize(450, 250);
setLayout(null);
l1 = new Label();
l1.setBounds(80, 50, 150, 20);
t1 = new TextArea();
t1.setBounds(80, 80, 300, 125);
t1.addKeyListener(this);
add(l1);
add(t1);
}
public void keyPressed(KeyEvent e)
{
int keyCode = e.getKeyCode();
String keyName = (keyCode == KeyEvent.VK_F1) ? "F1 Key Pressed" :
(keyCode == KeyEvent.VK_F2) ? "F2 Key Pressed" :
(keyCode == KeyEvent.VK_F3) ? "F3 Key Pressed" :
(keyCode == KeyEvent.VK_F4) ? "F4 Key Pressed" :
(keyCode == KeyEvent.VK_F5) ? "F5 Key Pressed" :
(keyCode == KeyEvent.VK_F6) ? "F6 Key Pressed" :
(keyCode == KeyEvent.VK_F7) ? "F7 Key Pressed" :
(keyCode == KeyEvent.VK_F8) ? "F8 Key Pressed" :
(keyCode == KeyEvent.VK_F9) ? "F9 Key Pressed" :
(keyCode == KeyEvent.VK_F10) ? "F10 Key Pressed" :
(keyCode == KeyEvent.VK_F11) ? "F11 Key Pressed" :
(keyCode == KeyEvent.VK_F12) ? "F12 Key Pressed" :
(keyCode == KeyEvent.VK_UP) ? "Up Arrow Pressed" :
(keyCode == KeyEvent.VK_DOWN) ? "Down Arrow Pressed" :
(keyCode == KeyEvent.VK_LEFT) ? "Left Arrow Pressed" :
(keyCode == KeyEvent.VK_RIGHT) ? "Right Arrow Pressed" :
"Key Pressed";
l1.setText(keyName);
}
public void keyReleased(KeyEvent e)
{
l1.setText("Key Released");
}
public void keyTyped(KeyEvent e)
{
l1.setText("Key Typed");
}
public static void main(String[] args)
{
practical10_1 pr10_1 = new practical10_1();
}
}

Output:

You might also like