-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSummation.java
More file actions
72 lines (56 loc) · 1.9 KB
/
Summation.java
File metadata and controls
72 lines (56 loc) · 1.9 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Summation extends JFrame {
JButton addButton, clear;
JTextField one, two, three;
Summation() {
super("Summation");
setSize(250,250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
add(new JLabel("First Number : "));
add(one = new JTextField(20));
add(new JLabel("Second Number : "));
add(two = new JTextField(20));
add(new JLabel("Third Number : "));
add(three = new JTextField(20));
add(addButton = new JButton("add"));
add(clear = new JButton("clear"));
addButton.addActionListener(new Inner());
clear.addActionListener(new Inner());
setVisible(true);
}
class Inner implements ActionListener {
@Override
public void actionPerformed(ActionEvent actionEvent)
{
if(actionEvent.getSource() == addButton) {
String s1 = one.getText();
int x = Integer.parseInt(s1);
String s2 = one.getText();
int y = Integer.parseInt(s1);
String s3 = one.getText();
int z = Integer.parseInt(s1);
int sum = x + y + z;
System.out.println(sum);
// int a = Integer.parseInt(textField1.getText());
// int b = Integer.parseInt(textField2.getText());
// int c = Integer.parseInt(textField3.getText());
//
// output.setText("" + (a+b+c));
}
else if(actionEvent.getSource() == clear) {
one.setText("");
two.setText("");
three.setText("");
}
}
}
//main method
public static void main(String[] args)
{
new Summation();
}
}