-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSwing_Add_Two_No.java
More file actions
53 lines (51 loc) · 1.52 KB
/
Swing_Add_Two_No.java
File metadata and controls
53 lines (51 loc) · 1.52 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
import javax.swing.*;
import java.awt.event.*;
public class Swing_Add_Two_No extends JFrame{
JLabel l1,l2,l3,l4;
JTextField t1,t2;
JButton b1;
public Swing_Add_Two_No(){}
public Swing_Add_Two_No(String s){
super(s);
}
public void setComponents(){
l1 = new JLabel("Addition of two number");
l2 = new JLabel("First number");
l3 = new JLabel("Second number");
l4 = new JLabel();
t1 = new JTextField();
t2 = new JTextField();
b1 = new JButton("ADD");
setLayout(null);
l1.setBounds(50,50,200,20);
l2.setBounds(50,80,200,20);
t1.setBounds(150,80,200,20);
l3.setBounds(50,130,200,20);
t2.setBounds(170,130,200,20);
b1.setBounds(80,180,100,20);
l4.setBounds(80, 240, 200, 20);
b1.addActionListener(new Handler());
add(l1);
add(l2);
add(l3);
add(l4);
add(t1);
add(t2);
add(b1);
}
class Handler implements ActionListener{
public void actionPerformed(ActionEvent e){
int a = Integer.parseInt(t1.getText());
int b = Integer.parseInt(t2.getText());
int s = a+b;
l4.setText("Addition is"+s);
}
}
public static void main(String[] args){
Swing_Add_Two_No jf = new Swing_Add_Two_No("Swing Add Two Number");
jf.setComponents();
jf.setSize(400,300);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}