-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactorilaAWT.java
More file actions
55 lines (41 loc) · 1.17 KB
/
FactorilaAWT.java
File metadata and controls
55 lines (41 loc) · 1.17 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
51
52
53
54
55
// Q Create AWT application to print factorial of number
import java.awt.*;
import java.awt.event.*;
public class FactorialAWT extends Frame implements ActionListener{
Label l1,l2;
TextField t1,t2;
Button b;
FactorialAWT(){
setLayout(new GridLayout(3,2));
l1 = new Label("Enter Number: ");
l2 = new Label("Result: ");
t1 = new TextField();
t2 = new TextField();
t2.setEditable(false);
b = new Button("Calculate");
add(l1); add(t1);
add(l2); add(t2);
add(b);
b.addActionListener(this);
setTitle("Factorial Calculator");
setSize(300,100);
setVisible(true);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
dispose();
}
});
}
@Override
public void actionPerformed(ActionEvent e){
int num = Integer.parseInt(t1.getText());
Long fact = 1L;
for(int i = 1; i <= num; i++){
fact *= i;
}
t2.setText(String.valueOf(fact));
}
public static void main(String[] args){
new FactorialAWT();
}
}