Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
38 views5 pages

R.Practical 10th

Advance java practical no. 10

Uploaded by

gourupatil88300
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)
38 views5 pages

R.Practical 10th

Advance java practical no. 10

Uploaded by

gourupatil88300
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/ 5

Subject - AJP [22517]

Practical No. 10: Write a program to demonstrate status of key on Applet window such as
KeyPressed, KeyReleased, KeyUp, KeyDown.
Performed By – Vedant Nawade
CO5I – 44
_________________________________________________________________________________________________________________________________

X - PROGRAM CODE
Q1------------------------
------------------------------------------- PROGRAM CODE -----------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
public class P10XCode1 extends Frame implements KeyListener
{
Label l;
TextArea a;
P10XCode1()
{
l = new Label();
l.setBounds (20, 50, 100, 20);
l.setBackground(Color.WHITE);
a = new TextArea();
a.setBounds (20, 80, 300, 100);
a.addKeyListener(this);
add(l);
add(a);
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 P10XCode1();
}
}
-------------------------------------------- PROGRAM OUTPUT --------------------------------------------------
Subject - AJP [22517]
Practical No. 10: Write a program to demonstrate status of key on Applet window such as
KeyPressed, KeyReleased, KeyUp, KeyDown.
Performed By – Vedant Nawade
CO5I – 44
_________________________________________________________________________________________________________________________________

X - PROGRAM CODE
Q2 ------------------------
------------------------------------------- PROGRAM CODE -----------------------------------------------------------
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class P10XCode2 extends Frame implements KeyListener


{
Label lb;
TextField tf;
P10XCode2()
{
lb = new Label();
lb.setSize(100,20);
tf= new TextField(40);
tf.addKeyListener(this);
add(lb);
add(tf);
setVisible(true);
setLayout(new FlowLayout());
setSize(500,100);
setTitle("Key Pressed Event With Speacial Keys ");
}
public void keyTyped(KeyEvent e)
{

}
public void keyPressed(KeyEvent e)
{
int key = e.getKeyCode();
switch (key)
{
case KeyEvent.VK_F1:
lb.setText(" F1 ");
break;
Subject - AJP [22517]
Practical No. 10: Write a program to demonstrate status of key on Applet window such as
KeyPressed, KeyReleased, KeyUp, KeyDown.
Performed By – Vedant Nawade
CO5I – 44
_________________________________________________________________________________________________________________________________

case KeyEvent.VK_F2:
lb.setText(" F2 ");
break;
case KeyEvent.VK_F3:
lb.setText(" F3 ");
break;
case KeyEvent.VK_F4:
lb.setText(" F4 ");
break;
case KeyEvent.VK_F5:
lb.setText(" F5 ");
break;
case KeyEvent.VK_UP:
lb.setText(" UP ");
break;
case KeyEvent.VK_DOWN:
lb.setText(" DOWN ");
break;
case KeyEvent.VK_LEFT:
lb.setText(" LEFT ");
break;
case KeyEvent.VK_RIGHT:
lb.setText(" RIGHT ");
break;
default:
lb.setText(" NO SPECIAL KEY ");
}
}
@Override
public void keyReleased(KeyEvent e)
{

}
public static void main(String[] args)
{
new P10XCode2();
}
}
-------------------------------------------- PROGRAM OUTPUT --------------------------------------------------
Subject - AJP [22517]
Practical No. 10: Write a program to demonstrate status of key on Applet window such as
KeyPressed, KeyReleased, KeyUp, KeyDown.
Performed By – Vedant Nawade
CO5I – 44
_________________________________________________________________________________________________________________________________

XIII. Exercise
Q3 ------------------------
------------------------------------------- PROGRAM CODE -----------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
class P10ExQ3 extends Frame implements ActionListener
{
Label L1 ,L2 , L3 ;
TextField T1, T2 ;
int s1 , s2, s3;
Button b;
TextField product;
P10ExQ3()
{
L1= new Label("Enter Two NUmbers In Box Seperatly For Multiplication
Of Them");
L1.setSize(10,20);
add(L1);
T1 = new TextField(10);
add(T1);
L2= new Label("*");
L2.setSize(10,20);
add(L2);
T2 = new TextField(10);
add(T2);
L3= new Label("=");
L3.setSize(10,20);
add(L3);
product = new TextField(10);
add(product);
b = new Button("Multiply The Numbers");
add(b);
b.addActionListener(this);
setSize (1000, 200);
Subject - AJP [22517]
Practical No. 10: Write a program to demonstrate status of key on Applet window such as
KeyPressed, KeyReleased, KeyUp, KeyDown.
Performed By – Vedant Nawade
CO5I – 44
_________________________________________________________________________________________________________________________________

setLayout (new FlowLayout(FlowLayout.LEFT,20,20));


setVisible (true);
}
public void actionPerformed(ActionEvent e)
{
s1= Integer.parseInt((T1.getText()));
s2 = Integer.parseInt(new String(T2.getText()));
s3= (s1 * s2);
product.setText(String.valueOf(s3));
}
public static void main(String[] args)
{
new P10ExQ3();
}
}

-------------------------------------------- PROGRAM OUTPUT --------------------------------------------------

You might also like