-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddition.java
More file actions
54 lines (50 loc) · 1.39 KB
/
Copy pathAddition.java
File metadata and controls
54 lines (50 loc) · 1.39 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
package Swing;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Addition {
public static void main(String[] args) {
new Add();
}
}
class Add extends JFrame {
JTextField t1,t2;
JButton a,s;
JLabel result;
public Add(){
t1=new JTextField(10);
t2=new JTextField(10);
a=new JButton("Add");
s=new JButton("Subtract");
result=new JLabel("Result");
setLayout(new FlowLayout());
setTitle("Addition");
setVisible(true);
setSize(400,400);
a.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
int s=a+b;
result.setText(s+"");
}
});
s.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
int d=a-b;
result.setText(d+"");
}
});
add(t1);
add(t2);
add(a);
add(s);
add(result);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}