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

PracticalNo10 2

This document describes a Java program that demonstrates key status events in an Applet window. It includes a graphical user interface with labels, text fields, and a button to multiply two numbers entered by the user. The program handles input validation and displays the result or an error message accordingly.

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)
12 views2 pages

PracticalNo10 2

This document describes a Java program that demonstrates key status events in an Applet window. It includes a graphical user interface with labels, text fields, and a button to multiply two numbers entered by the user. The program handles input validation and displays the result or an error message accordingly.

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_2 extends Frame implements ActionListener


{
Label l1, l2, l3;
TextField t1, t2;
Button b1;
practical10_2()
{
setTitle("ActionListener");
setVisible(true);
setSize(310,200);
setLayout(null);

l1 = new Label("Enter Number One: ");


l1.setBounds(50,50,100,20);
l2 = new Label("Enter Number Two: ");
l2.setBounds(50,80,100,20);
l3 = new Label("Result is: ");
l3.setBounds(50,140,200,20);
t1 = new TextField();
t1.setBounds(160,50,100,20);
t2 = new TextField();
t2.setBounds(160,80,100,20);
b1 = new Button("Multipy");
b1.setBounds(50,110,80,20);
add(l1);
add(t1);
add(l2);
add(t2);
add(b1);
add(l3);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
try
{
double no1 = Double.parseDouble(t1.getText());
double no2 = Double.parseDouble(t2.getText());
double result = no1 * no2;
l3.setText("Result is: "+result);
}
catch (NumberFormatException ex)
{
l3.setText("Invalid input. Please enter numbers.");
}
}
public static void main(String args[])
{
practical10_2 pr10_2 = new practical10_2();
}
}

Output:

You might also like