Home » Sometech » Develop an applet that receives an integer in one text field, and computes its factorial value and return it in another text field, when the button named “Compute” is clicked.

Develop an applet that receives an integer in one text field, and computes its factorial value and return it in another text field, when the button named “Compute” is clicked.

Java Coding

import java.awt.*;

import java.awt.event.*;

import java.applet.*;

public class myevent11 extends Applet implements ActionListener

{

Label   l1,l2;

Button b1;

TextField t1,t2;

 

public void init()

{

setLayout(null);

 

l1 = new Label(“Enter the number”);

l2 = new Label(“Result”);

 

t1 = new TextField(30);

t2 = new TextField(30);

 

b1 = new Button(“Compute”);

 

add(t1);

add(t2);

 

add(l1);

add(l2);

 

add(b1);

 

 

l1.setBounds(50,100,150,30);

l2.setBounds(50,150,150,30);

 

 

t1.setBounds(250,100,150,30);

t2.setBounds(250,150,150,30);

 

b1.setBounds(230,240,100,30);

 

 

b1.addActionListener(this);

 

}

public void actionPerformed(ActionEvent e)

{

if(e.getActionCommand()==”Clicked”)

{

int a = Integer.parseInt(t1.getText());

int fact =1;

for (int i= 1; i<=a; i++)

{

fact=fact*i;

}

t2.setText(String.valueOf(fact));

}

}

}

 

/*<applet code=”myevent11″ width =1000 height =1000></applet>*/

 

 

Advertisements

SoME Tech

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

%d bloggers like this: