import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*
<applet code=prg7
width=500 height=50>
</applet>
*/
public class prg7 extends Applet implements ActionListener
{
int i,fact,no;
Label l1=new Label("N :");
Label l2=new Label("Factorial :");
TextField tf1=new TextField();
TextField tf2=new TextField();
Button b1=new Button("Next");
public void init()
{
fact=1;
b1.addActionListener(this);
tf1.setText(null);
setLayout(null);
add(l1);
add(tf1);
add(tf2);
add(l2);
add(b1);
l1.setBounds(10,10,40,20);
tf1.setBounds(50,10,80,20);
l2.setBounds(150,10,100,20);
tf2.setBounds(250,10,80,20);
b1.setBounds(330,10,80,20);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
{
fact=1;
no=Integer.parseInt(tf1.getText());
for(i=no;i>=1;i--)
{
fact=fact*i;
}
tf2.setText(String.valueOf(fact));
}
}
public void destroy()
{
i=0;
}
public void paint(Graphics g)
{
showStatus("Sanjay Chauhan");
}
}
java Applet Factorial Code
Reviewed by Unknown
on
5:48 pm
Rating:
No comments: