import java.applet.Applet;
import
java.awt.Button;
import
java.awt.Color;
import
java.awt.Frame;
import
java.awt.Label;
import
java.awt.TextField;
import
java.awt.event.ActionEvent;
import
java.awt.event.ActionListener;
import
javax.swing.JOptionPane;
import
static javax.swing.JOptionPane.WARNING_MESSAGE;
public class
FactApplet extends Applet implements ActionListener {
Label one=new Label("Enter any
No:");
Label Two=new Label("Factorial
:");
TextField tf1=new TextField();
TextField tf2=new TextField();
Button Compute=new
Button("Compute");
Frame f=new Frame("Calculator to
Find Factorial");
int p;
@Override
public void init() {
one.setBackground(Color.MAGENTA);
one.setBounds(100, 100, 100, 30);
f.add(one);
tf1.setBackground(Color.PINK);
tf1.setBounds(220, 100, 150, 30);
f.add(tf1);
tf1.addActionListener(this);
Two.setBackground(Color.MAGENTA);
Two.setBounds(100, 150, 100, 30);
f.add(Two);
tf2.setBackground(Color.PINK);
tf2.setBounds(220, 150, 150, 30);
f.add(tf2);
Compute.setBackground(Color.PINK);
Compute.setBounds(200, 200, 100, 20);
f.add(Compute);
Compute.addActionListener((ActionListener) this);
f.setSize(500,300);
f.setLayout(null);
f.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent
ae){
int i,n;
p=1;
n=Integer.parseInt(tf1.getText());
if (n==0){
p=0;
JOptionPane.showMessageDialog(f,
"You have Provided Null Value","Inane warning",
JOptionPane.WARNING_MESSAGE);
}
if
(ae.getActionCommand().equals("Compute")){
for(i=1;i<=n;i++){
p=p*i;
}
}
tf2.setText(Integer.toString(p));
repaint();
}
}
OUTPUT :
No comments:
Post a Comment