-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathfactorialbutton.java
More file actions
50 lines (44 loc) · 1.2 KB
/
factorialbutton.java
File metadata and controls
50 lines (44 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.awt.*;
import java.awt.event.*;
class FrameFact extends Frame implements ActionListener {
Button b1;
Label l1;
TextField t1;
String msg = " ";
FrameFact() {
l1 = new Label("Enter the no.");
t1 = new TextField(30);
b1 = new Button("Compute Factorial");
setLayout(new FlowLayout());
add(l1);
add(t1);
add(b1);
b1.addActionListener(this);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent ae) {
setVisible(false);
}
});
}
public void actionPerformed(ActionEvent ae) {
int fact = 1;
String s = t1.getText();
int n = Integer.parseInt(s);
for (int i = 1; i <= n; i++)
fact = fact * i;
msg = "The Factorial is=" + fact;
repaint();
}
public void paint(Graphics g) {
g.drawString(msg, 100, 100);
}
}
public class factorialbutton {
public static void main(String[] args) {
// TODO Auto-generated method stub
FrameFact o1 = new FrameFact();
o1.setTitle("Factorial");
o1.setVisible(true);
o1.setSize(400, 400);
}
}