You are on page 1of 2

Advanced Java Programming (22517)

Practical No. 10: Write a program to demonstrate status of key on


Applet window such as KeyPressed, KeyReleased,
KeyUp, KeyDown.

I. Practical Significance:
A KeyEvent is generated when keyboard input occurs. When key is pressed, released
or typed, key event is generated. Students will be able to understand the method to
register an object and handle various key of Keyboards.

II. Relevant Program Outcomes (POs)


 Basic knowledge: Apply knowledge of basic mathematics, sciences and basic
engineering to solve the computer group related problems.
 Discipline knowledge: Apply Computer Programming knowledge to solve the
computer group related problems.
 Experiments and practice: Plan to perform experiments and practices to use the
results to solve the computer group related problems.
 Engineering tools: Apply relevant Computer programming / technologies and
tools with an understanding of the limitations.
 Individual and Team work: Function effectively as a leader and team member in
diverse/multidisciplinary teams.
 Communication: Communicate effectively in oral and written form.

III. Competency and Practical skills


Using this Practical, students will be able to generate different events .Also, they are
able to implement various methods for appropriate listener class and write and
execute programs accordingly.

IV. Relevant Course Outcome(s)


 Handle Events of AWT and Swing Components.
 Develop programs to handle events in Java Programming.

V. Practical Outcome (PrOs)


Write a program to demonstrate status of key on Applet window such as KeyPressed,
Key Released, KeyUp, and KeyDown

VI. Relevant Affective domain related Outcome(s)


1. Follow precautionary measures.
2. Follow naming conventions.
3. Follow ethical practices.

VII. Minimum Theoretical Background


When keyboard input is occurred, a KeyEvent is generated. There are mainly three
types of key events that are recognized by integer constants as follows:

KEY_PRESSED, KEY_RELEASED, KEY_TYPED

When key is pressed or released, first two events are generated. When character is
pressed, the last event occurs. All Keys do not generate character. E.g. Shift Key

Maharashtra state Board of Technical Education 53


Advanced Java Programming (22517)

InputEvent is super class of KeyEvent.

The class which processes the KeyEvent should implement KeyListener interface.

The object of that class must be registered with a component. The object can be
registered using the addKeyListener () method.

Methods of KeyListener interface:

void keyPressed(KeyEvent e) : Invoked when a key is pressed

void keyReleased(KeyEvent e) : Invoked when a key has been released

void keyTyped(KeyEvent e) : Invoked when a key has been typed

VIII. Resources required (Additional)–

Nil

IX. Resources used (Additional)

Sr.
Name of Resource Broad Specification Quantity Remarks (If any)
No.
1

X. Program Code: Teacher must assign a separate program statement to group of


3-4 students.
1. Write a program to generate KeyEvent when a key is pressed and display “Key
Pressed” message.
2. Develop a program which will implement special keys such as function keys and
arrow keys.

Maharashtra state Board of Technical Education 54

You might also like