Applet to calculate Factorial Value

Aim: 
To develop an applet that receives an integer in one text field, and computes as factorial value and returns it in another text field, when the button named “Compute” is clicked.

Description:
Write a class by extending Applet class and implement ActionListener. Attach two textfileds and a button to the applet. Attach actionlistener to the button and provide actionPerformed() method to compute factorial value. First textfield is used for entering a number and after clicking on the button the result will be displayed on the second textfield.

Program:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.Applet;
/*<applet code="App2.class" height=100 width=500></applet>*/
public class App2 extends Applet implements ActionListener
{ JTextField tf1;
JTextField tf2;
JButton b;
JLabel l;
public void init()
{
l =new JLabel("Enter the number & press the button");
tf1=new JTextField("",5);
tf2=new JTextField("",10);
b=new JButton("Compute");
add(l);
add(tf1);
add(tf2);
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
String str1;
int fact=1;
if(str=="Compute")
{
int n=Integer.parseInt(tf1.getText());
for(int i=1;i<=n;i++)
fact=fact*i;
str1=""+fact;
tf2.setText(str1);
}
}
}