0% found this document useful (0 votes)
7 views15 pages

Java Applet Programs for Calculations

The document contains three Java applet programs demonstrating different functionalities. The first program performs mathematical calculations (sin, cos, log, etc.) based on user input, the second calculates employee details including salary and deductions, and the third computes student details such as total marks and pass/fail status. Each program includes user interface elements like buttons and text fields, and handles actions through event listeners.

Uploaded by

Tamil Azhagan
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)
7 views15 pages

Java Applet Programs for Calculations

The document contains three Java applet programs demonstrating different functionalities. The first program performs mathematical calculations (sin, cos, log, etc.) based on user input, the second calculates employee details including salary and deductions, and the third computes student details such as total marks and pass/fail status. Each program includes user interface elements like buttons and text fields, and handles actions through event listeners.

Uploaded by

Tamil Azhagan
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

TextField Program: 9(sample program to Math calculation in button)

import [Link].*;
import [Link].*;
import [Link].*;
/*<applet code="[Link]" width=500 height=300></applet>*/
public class b8 extends Applet implements ActionListener
{
Button b1,b2,b3,b4,b5,b6,b7;
Label l1,l2;
TextField t1,t2;
double x, y;
public void init()
{
b1=new Button("sin");
b2=new Button("cos");
b3=new Button("log");
b4=new Button("ln");
b5=new Button("sq");
b6=new Button("sqrt");
b7=new Button("clear");
l1=new Label("x");
l2=new Label("y");
t1=new TextField(8);
t2=new TextField(8);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
add(l1);
add(t1);
add(l2);
add(t2);
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
add(b7);
}
public void actionPerformed(ActionEvent e)
{
String s1=[Link]();
Graphics g=getGraphics();
if([Link]("sin"))
{
x=[Link]([Link]());
y=[Link](x);
[Link]([Link](y));
}
else if([Link]("cos"))
{
x=[Link]([Link]());
y=[Link](x);
[Link]([Link](y));
}
else if([Link]("log"))
{
x=[Link]([Link]());
y=[Link](x);
[Link]([Link](y));
}
else if([Link]("ln"))
{
x=[Link]([Link]());
y=[Link](x);
[Link]([Link](y));
}
else if([Link]("sq"))
{
x=[Link]([Link]());
y=[Link](x,2);
[Link]([Link](y));
}
else if([Link]("sqrt"))
{
x=[Link]([Link]());
y=[Link](x);
[Link]([Link](y));
}
if([Link]("clear"))
{
[Link](" ");
[Link](" ");
}
}
}
Compile:
F:\jdk-1.0.6\bin>javac [Link]
Run:
F:\jdk-1.0.6\bin>appletviewer [Link]
Output:

Notes:-
TextField Program: 11(program for create a employee details)
import [Link].*;
import [Link].*;
import [Link].*;
/* <applet code="[Link]" width=500 height=500>
</applet>*/
public class tf11 extends Applet implements ActionListener
{
Button b1,b2;
Label l1,l2,l3,l4,l5,l6,l7,l8,l9;
TextField t1,t2,t3,t4,t5,t6,t7,t8,t9;
public void init()
{
b1=new Button("CALCULATE");
b2=new Button("CLEAR");
l1=new Label("Employee name");
l2=new Label("Employee no");
l3=new Label("Salary");
l4=new Label("HRA");
l5=new Label("DA");
l6=new Label("TA");
l7=new Label("IT");
l8=new Label("Gross pay");
l9=new Label("net pay");
t1=new TextField(10);
t2=new TextField(10);
t3=new TextField(10);
t4=new TextField(10);
t5=new TextField(10);
t6=new TextField(10);
t7=new TextField(10);
t8=new TextField(10);
t9=new TextField(10);
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l4);
add(t4);
add(l5);
add(t5);
add(l6);
add(t6);
add(l7);
add(t7);
add(l8);
add(t8);
add(l9);
add(t9);
add(b1);
add(b2);
[Link](this);
[Link](this);
}
public void actionPerformed(ActionEvent e)
{
String s=[Link]();
double sal, hra, da, it, ta, gross, net;
[Link]();
[Link]();
sal=[Link]([Link]());
if([Link]("CALCULATE"))
{
hra=sal*0.2;
[Link]([Link](hra));
da=sal*0.4;
[Link]([Link](da));
ta=sal*0.6;
[Link]([Link](ta));
it=sal*0.8;
[Link]([Link](it));
gross=hra+da+ta;
[Link]([Link](gross));
net=gross-it;
[Link]([Link](net));
}
else if(equals("CLEAR"))
{
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
}
}
}
Compile:
F:\jdk-1.0.6\bin>javac [Link]
Run:
F:\jdk-1.0.6\bin>appletviewer [Link]
Output:-

Notes:-
TextField Program: 12(sample program for student details)
import [Link].*;
import [Link].*;
import [Link].*;
/*<applet code="[Link]" width=500 height=500> </applet>*/
public class tf12 extends Applet implements ActionListener
{
Button b1,b2;
Label l1,l2,l3,l4,l5,l6,l7,l8,l9;
TextField t1,t2,t3,t4,t5,t6,t7,t8,t9;
public void init()
{
b1=new Button("CALCULATE");
b2=new Button("CLEAR");
l1=new Label("Student name");
l2=new Label("Student no");
l3=new Label("Standard");
l4=new Label("mark1");
l5=new Label("mark2");
l6=new Label("mark3");
l7=new Label("total");
l8=new Label("avg");
l9=new Label("result");
t1=new TextField(10);
t2=new TextField(10);
t3=new TextField(10);
t4=new TextField(10);
t5=new TextField(10);
t6=new TextField(10);
t7=new TextField(10);
t8=new TextField(10);
t9=new TextField(10);
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l4);
add(t4);
add(l5);
add(t5);
add(l6);
add(t6);
add(l7);
add(t7);
add(l8);
add(t8);
add(l9);
add(t9);
add(b1);
add(b2);
[Link](this);
[Link](this);
}
public void actionPerformed(ActionEvent e)
{
String s=[Link]();
if([Link]("CALCULATE"))
{
int sno,std,m1,m2,m3,tot;
double avg;
String sname, fname, res;
sname=[Link]();
sno=[Link]([Link]());
std=[Link]([Link]());
m1=[Link]([Link]());
m2=[Link]([Link]());
m3=[Link]([Link]());
tot=(m1+m2+m3);
[Link]([Link](tot));
avg=(tot/3);
[Link]([Link](avg));
if(m1>=50 && m2>=50 && m3>=50)
{
[Link]("pass");
}
else{
[Link]("Fail");
}
}
else if([Link]("CLEAR"))
{
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
}
}
}

Compile:
F:\jdk-1.0.6\bin>javac [Link]
Run:
F:\jdk-1.0.6\bin>appletviewer [Link]

Output:-
Notes:-

You might also like