Program 4 Wt
Program 4 Wt
Objective: Write a Java applet to display the Application Program screen i.e. calculator and other.
Theory:
Applet is a special type of program that is embedded in the web page to generate the dynamic
content.
PROGRAM:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
b1 = new Button("+");
b2 = new Button("-");
b3 = new Button("*");
b4 = new Button("/");
add(t1);
add(t2);
add(t3);
add(b1);
add(b2);
add(b3);
add(b4);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
String s1 = t1.getText();
String s2 = t2.getText();
double a = Double.parseDouble(s1);
double b = Double.parseDouble(s2);
if (ae.getSource() == b1) {
t3.setText(String.valueOf(a + b));
} else if (ae.getSource() == b2) {
t3.setText(String.valueOf(a - b));
} else if (ae.getSource() == b3) {
t3.setText(String.valueOf(a * b));
} else if (ae.getSource() == b4) {
t3.setText(String.valueOf(a / b));
}
}
}
OUTPUT: