/*Applet that displays two TextFields and Calclates Factorial and displays in other Text Field*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class simpleApplet extends Applet
{
public Button k;
public TextField a,b;
public void init()
{
a=new TextField(20);
b=new TextField(20);
k=new Button("Compute");
add(k);
add(a);
add(b);
}
public int fact(int k)
{
int result=1;
for(int i=1;i<=k;i++)
{
result*=i;
}
return result;
}
public void start()
{
k.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int s=new Integer(a.getText()).intValue();
int t=fact(s);
b.setText(String.valueOf(t));
}
});
}
}
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class simpleApplet extends Applet
{
public Button k;
public TextField a,b;
public void init()
{
a=new TextField(20);
b=new TextField(20);
k=new Button("Compute");
add(k);
add(a);
add(b);
}
public int fact(int k)
{
int result=1;
for(int i=1;i<=k;i++)
{
result*=i;
}
return result;
}
public void start()
{
k.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int s=new Integer(a.getText()).intValue();
int t=fact(s);
b.setText(String.valueOf(t));
}
});
}
}
1 comments:
it is not like that dude...
sir asked in different way
check my program once..
Post a Comment