-
Notifications
You must be signed in to change notification settings - Fork 0
/
Swing1
82 lines (66 loc) · 1.51 KB
/
Swing1
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
73
74
75
76
77
78
79
80
81
82
// program for incrementing and decrementing
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Swing1 implements ActionListener{
JButton e3,e1,e2;
JTextField t,t1;
JPanel p;
JFrame f;
Swing1(){
f=new JFrame();
t1=new JTextField(10);
t1.setBounds(200, 200, 50, 50);
e1=new JButton("increment");
e1.setBounds(300, 300, 50, 50);
e2=new JButton("decrement");
e2.setBounds(300, 320, 50, 50);
e3=new JButton("clear");
e3.setBounds(250,130,30,30);
p=new JPanel();
p.add(t1);
p.add(e3);
p.add(e1);
p.add(e2);
f.setContentPane(p);
e1.addActionListener(this);
e2.addActionListener(this);
e3.addActionListener(this);
f.setSize(200, 200);
f.setVisible(true);
f.setLayout(null);
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==e1)
{
String s=t1.getText();
int n=Integer.parseInt(s);
int sum=0;
sum=n+1;
String r=Integer.toString(sum);
t1.setText(r);
}
if(e.getSource()==e2)
{
String s = t1.getText();
int r= Integer.parseInt(s);
int sum=0;
sum=r-1;
String aa=Integer.toString(sum);
t1.setText(aa);
}
if(e.getSource()==e3)
{
String s=t1.getText();
int r=Integer.parseInt(s);
r=0;
String a=Integer.toString(r);
t1.setText(a);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Swing1();
}
}