-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui1.java
More file actions
197 lines (181 loc) · 3.49 KB
/
Copy pathgui1.java
File metadata and controls
197 lines (181 loc) · 3.49 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import java.awt.*;
import java.awt.event.*;
class gui1 implements ActionListener
{
Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16;
TextField tf1;
public gui1()
{
Frame f=new Frame("Calculater");
f.setSize(300,150);
b1=new Button("1");
b1.addActionListener(this);
b2=new Button("2");
b2.addActionListener(this);
b3=new Button("3");
b3.addActionListener(this);
b4=new Button("+");
b4.addActionListener(this);
b5=new Button("4");
b5.addActionListener(this);
b6=new Button("5");
b6.addActionListener(this);
b7=new Button("6");
b7.addActionListener(this);
b8=new Button("-");
b8.addActionListener(this);
b9=new Button("7");
b9.addActionListener(this);
b10=new Button("8");
b10.addActionListener(this);
b11=new Button("9");
b11.addActionListener(this);
b12=new Button("*");
b12.addActionListener(this);
b13=new Button("c");
b13.addActionListener(this);
b14=new Button("0");
b14.addActionListener(this);
b15=new Button("/");
b15.addActionListener(this);
b16=new Button("=");
b16.addActionListener(this);
Panel p1=new Panel();
Panel p2=new Panel();
p1.setLayout(new BorderLayout());
p2.setLayout(new GridLayout(4,4));
f.add(p1,BorderLayout.NORTH);
//p1.setBackground(Color.red);
tf1=new TextField(12);
p1.add(tf1);
//p1.add(p2);
p2.add(b1);
p2.add(b2);
p2.add(b3);
p2.add(b4);
p2.add(b5);
p2.add(b6);
p2.add(b7);
p2.add(b8);
p2.add(b9);
p2.add(b10);
p2.add(b11);
p2.add(b12);
p2.add(b13);
p2.add(b14);
p2.add(b15);
p2.add(b16);
f.add(p2);
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
p1.setVisible(true);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
String t=tf1.getText();
tf1.setText(t+"1");
}
else
if(e.getSource()==b2)
{
String t=tf1.getText();
tf1.setText(t+"2");
}
else
if(e.getSource()==b3)
{
String t=tf1.getText();
tf1.setText(t+"3");
}
else
if(e.getSource()==b4)
{
String t=tf1.getText();
tf1.setText(t+"+");
}
else
if(e.getSource()==b5)
{
String t=tf1.getText();
tf1.setText(t+"4");
}
else
if(e.getSource()==b6)
{
String t=tf1.getText();
tf1.setText(t+"5");
}
else
if(e.getSource()==b7)
{
String t=tf1.getText();
tf1.setText(t+"6");
}
else
if(e.getSource()==b8)
{
String t=tf1.getText();
tf1.setText(t+"-");
}
else
if(e.getSource()==b9)
{
String t=tf1.getText();
tf1.setText(t+"7");
}
else
if(e.getSource()==b10)
{
String t=tf1.getText();
tf1.setText(t+"8");
}
else
if(e.getSource()==b11)
{
String t=tf1.getText();
tf1.setText(t+"9");
}
else
if(e.getSource()==b12)
{
String t=tf1.getText();
tf1.setText(t+"*");
}
else
if(e.getSource()==b13)
{
String t=tf1.getText();
tf1.setText(" ");
}
else
if(e.getSource()==b14)
{
String t=tf1.getText();
tf1.setText(t+"0");
}
else
if(e.getSource()==b15)
{
String t=tf1.getText();
tf1.setText(t+"/");
}
else
if(e.getSource()==b16)
{
String t=tf1.getText();
tf1.setText(t+"=");
}
}
public static void main(String args[])
{
new gui1();
}
}