-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSimpcalc.java
More file actions
319 lines (283 loc) · 13.8 KB
/
Simpcalc.java
File metadata and controls
319 lines (283 loc) · 13.8 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
import javax.swing.*;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* @author Siddharth1
*/
public class Simpcalc extends JFrame {
/**
* Creates new form simpcalc
*/
public Simpcalc() {
initComponents();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private JPanel jPanel1;
private JTextField t1;
private JTextField t2;
private JLabel l1;
private JButton b1;
private JButton b2;
private JButton b3;
private JButton b4;
private JButton jButton5;
private JButton jButton6;
private JLabel jLabel1;
// End of variables declaration//GEN-END:variables
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new JPanel();
t1 = new JTextField();
t2 = new JTextField();
l1 = new JLabel();
b1 = new JButton();
b2 = new JButton();
b3 = new JButton();
b4 = new JButton();
jButton5 = new JButton();
jButton6 = new JButton();
jLabel1 = new JLabel();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(204, 204, 255));
jPanel1.setBackground(new java.awt.Color(204, 204, 255));
jPanel1.setBorder(BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
jPanel1.setToolTipText("");
t1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
t1ActionPerformed(evt);
}
});
l1.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
l1.setText("Answer:: ");
b1.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
b1.setText("ADD");
b1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b1ActionPerformed(evt);
}
});
b2.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
b2.setText("SUBTRACT");
b2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b2ActionPerformed(evt);
}
});
b3.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
b3.setText("MULTIPLY");
b3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b3ActionPerformed(evt);
}
});
b4.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
b4.setText("DIVIDE");
b4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b4ActionPerformed(evt);
}
});
jButton5.setBackground(new java.awt.Color(0, 51, 51));
jButton5.setForeground(new java.awt.Color(102, 102, 102));
jButton5.setText("RESET");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
jButton6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jButton6.setForeground(new java.awt.Color(255, 51, 0));
jButton6.setText("EXIT");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});
GroupLayout jPanel1Layout = new GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(85, 85, 85)
.addComponent(jButton5)
.addGap(44, 44, 44)
.addComponent(jButton6)
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(39, 39, 39)
.addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
.addComponent(b1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(b3, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 72, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
.addComponent(b2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(b4, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(59, 59, 59))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(49, 49, 49)
.addComponent(t1, GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(t2, GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE)
.addGap(46, 46, 46))
.addGroup(GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(l1, GroupLayout.PREFERRED_SIZE, 126, GroupLayout.PREFERRED_SIZE)
.addGap(102, 102, 102))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
.addComponent(t2, GroupLayout.DEFAULT_SIZE, 36, Short.MAX_VALUE)
.addComponent(t1))
.addGap(25, 25, 25)
.addComponent(l1)
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(b1)
.addComponent(b2))
.addGap(34, 34, 34)
.addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(b3)
.addComponent(b4))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 52, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jButton5)
.addComponent(jButton6)))
);
jLabel1.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
jLabel1.setText("CALCULATOR");
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGap(155, 155, 155)
.addComponent(jLabel1)
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
//GEN-FIRST:event_jButton5ActionPerformed
// TODO add your handling code here:
t1.setText(null);
t2.setText(null);
l1.setText(null);
}//GEN-LAST:event_jButton5ActionPerformed
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
//GEN-FIRST:event_jButton6ActionPerformed
// TODO add your handling code here:
System.exit(0);
}//GEN-LAST:event_jButton6ActionPerformed
private void b1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
//GEN-FIRST:event_b1ActionPerformed
float a = Float.parseFloat(t1.getText());
float b = Float.parseFloat(t2.getText());
float c = a + b;
l1.setText(c + " ");
//GEN-LAST:event_b1ActionPerformed
} catch (NumberFormatException e) {
System.err.println(e);
}
}
private void b2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
//GEN-FIRST:event_b2ActionPerformed
float a = Float.parseFloat(t1.getText());
float b = Float.parseFloat(t2.getText());
float c = a - b;
l1.setText(c + " ");
//GEN-LAST:event_b2ActionPerformed
} catch (NumberFormatException e) {
System.err.println(e);
}
}
private void b3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
//GEN-FIRST:event_b3ActionPerformed
float a = Float.parseFloat(t1.getText());
float b = Float.parseFloat(t2.getText());
float c = a * b;
l1.setText(c + " ");
//GEN-LAST:event_b3ActionPerformed
} catch (NumberFormatException e) {
System.err.println(e);
}
}
private void b4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
//GEN-FIRST:event_b4ActionPerformed
float a = Float.parseFloat(t1.getText());
float b = Float.parseFloat(t2.getText());
float c = a / b;
l1.setText(c + " ");
//GEN-LAST:event_b4ActionPerformed
} catch (NumberFormatException e) {
System.err.println(e);
}
}
private void t1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_t1ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Simpcalc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Simpcalc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Simpcalc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Simpcalc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Simpcalc().setVisible(true);
}
});
}
}