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

Experiment 1 Output

The document contains a Java program that demonstrates the use of a KeyListener in a graphical user interface. It creates a window with a label and a text area, updating the label based on key events (pressed, released, typed). The program is structured with a main method that initializes the KeyListener_Example class.

Uploaded by

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

Experiment 1 Output

The document contains a Java program that demonstrates the use of a KeyListener in a graphical user interface. It creates a window with a label and a text area, updating the label based on key events (pressed, released, typed). The program is structured with a main method that initializes the KeyListener_Example class.

Uploaded by

piyush.thorat24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

EXPERIMENT 1

SOURCE CODE:
import java.awt.*;
import java.awt.event.*;
public class KeyListener_Example extends Frame implements KeyListener {
Label l;
TextArea area;
KeyListener_Example() {
l = new Label();
l.setBounds (20, 50, 100, 20);
area = new TextArea();
area.setBounds (20, 80, 300, 300);
area.addKeyListener(this);
add(l);
add(area);
setSize (400, 400);
setLayout (null);
setVisible (true);
}
public void keyPressed (KeyEvent e) {
l.setText ("Key Pressed");
}
public void keyReleased (KeyEvent e) {
l.setText ("Key Released");
}
public void keyTyped (KeyEvent e) {
l.setText ("Key Typed");
}

public static void main(String[] args) {


new KeyListener_Example();
}
}

OUTPUT:

You might also like