Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

import java.awt.

*;
import java.awt.event.*;
public class buttonfactdemo extends Frame
{
TextField t1;
Label l1;
Button b1,b2;
int fact=1;
buttonfactdemo()
{
t1=new TextField(35);
l1=new Label("Factorial value is:");
b1=new Button("Factorial");
b2=new Button("Cancel");
add(l1);
add(t1);
add(b1);
add(b2);
setTitle("Factorial value");
setSize(500,500);
setLayout(new FlowLayout());
setVisible(true);
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
int n = Integer.parseInt(t1.getText());
for(int i=1;i<=n;i++)
fact=fact*i;
l1.setText("Factorial value is: "+fact);
}});
}
public static void main(String[] args)
{
new buttonfactdemo();
}}

You might also like