33% found this document useful (3 votes)
3K views4 pages

Ayush Practical No 10

This document contains code for three Java programs that demonstrate different key events: 1) A program that displays "Key Pressed" when any key is pressed. 2) A program that accepts two numbers from text fields and displays their product when a "Multiply" button is clicked. 3) No summary provided for the third program.

Uploaded by

nstrnsdtn
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
33% found this document useful (3 votes)
3K views4 pages

Ayush Practical No 10

This document contains code for three Java programs that demonstrate different key events: 1) A program that displays "Key Pressed" when any key is pressed. 2) A program that accepts two numbers from text fields and displays their product when a "Multiply" button is clicked. 3) No summary provided for the third program.

Uploaded by

nstrnsdtn
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/ 4

ADVANCE JAVA PROGRAMMING

Name :- Ayush Maroti Wadje Class : - CO5I


Roll No :- 76

P No 10 :- Write a Program To Demonstrate Status Of Key On Applet


Window Such As KeyPressed, KeyReleased, KeyUp, KeyDown.

X. Program Code :

1. Write a Program To Generate KeyEvent When a Key Is Pressed And Display


“Key Pressed” Message.

Code :-

import java.awt.*;
import java.awt.event.*;
public class KeyExample1 extends Frame implements KeyListener {
Label L;
TextArea TA;
KeyExample1() {
L=new Label();
L.setBounds(50,55,80,35);
TA=new TextArea();
TA.setBounds(10,10,15,15);
TA.addKeyListener(this);
add(L);
add(TA);
}
public void keyPressed(KeyEvent e)
{
L.setText("Key Pressed");

1
}
public void keyTyped(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
public static void main(String args[])
{
KeyExample1 ke=new KeyExample1();
ke.setSize(400,450);
ke.setVisible(true);
}
}
Output :-

2
XIII. Exercise.
3. Develop a Program To Accept Two Numbers And Display Product Of Two
Numbers When User Pressed “Multiply” Button.

Code :-
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
public class KeyExample2 extends Frame implements ActionListener{
TextField T1,T2,T3;
Label L1,L2,L3;
Button b=new Button("Multiply");
KeyExample2() {
setLayout(new FlowLayout());
T1=new TextField(15);
T2=new TextField(15);
T3=new TextField(15);
L1=new Label("FIRST NO:-");
L2=new Label("SECOND NO:-");
L3=new Label("PRODUCT:-");
add(L1);
add(T1);
add(L2);
add(T2);
add(b);
add(L3);
add(T3);
b.addActionListener(this);

3
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b) {
int n1=Integer.parseInt(T1.getText());
int n2=Integer.parseInt(T2.getText());
T3.setText(""+(n1*n2));
}
}
public static void main(String args[]) {
KeyExample2 ke=new KeyExample2();
ke.setVisible(true);
ke.setSize(450,400);

}
}

Output :-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy