-
Notifications
You must be signed in to change notification settings - Fork 0
/
add two number
61 lines (47 loc) · 1.16 KB
/
add two number
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
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import javax.swing.JTextField;
public class Hello
{
public static void main(String arc[])
{
box ob=new box();
ob.setVisible(true);
ob.setSize(500,500);
ob.shown();
}
}
class box extends JFrame
{
public box()
{
}
JTextField a1=new JTextField(10);
JTextField a2=new JTextField(10);
JLabel l1=new JLabel("ADD two Number");
JButton b1=new JButton("ADD"); JLabel ms=new JLabel();
public void shown()
{ setLayout(new FlowLayout());
add(l1);
add(a1);
add(a2);
add(b1);
JLabel s=new JLabel(a1.getText());
add(s);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
int sd=Integer.parseInt(a1.getText());
int sf=Integer.parseInt(a2.getText());
int m=sd+sf;
ms.setText(m+"");
add(ms);setVisible(true);
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}