-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculatorMenu.java
More file actions
330 lines (283 loc) · 9.24 KB
/
CalculatorMenu.java
File metadata and controls
330 lines (283 loc) · 9.24 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
320
321
322
323
324
325
326
327
328
329
330
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CalculatorMenu
{
static boolean radians = true;
static double deltaX = 1E-4;
static double dX = 1E-10;
static class memoryMenuSelected implements ActionListener{
public void actionPerformed(ActionEvent e) {
JFrame memoryFrame = new JFrame("Memory");
memoryFrame.setVisible(true);
memoryFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
memoryFrame.setSize(320, 200);
JPanel memoryPane = new JPanel(new GridBagLayout());
JScrollPane scrollPane = new JScrollPane(memoryPane);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(2, 0, 2, 0);
for(int g = 0; g < CalculatorOperations.memory.size(); g++)
{
c.gridy = g;
memoryPane.add(new JTextArea(CalculatorOperations.memory.get(g), 1, 25), c);
}
memoryFrame.setContentPane(scrollPane);
}
}
static class aboutMenuSelected implements ActionListener{
public void actionPerformed(ActionEvent e){
JFrame aboutFrame = new JFrame("About");
aboutFrame.setVisible(true);
aboutFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel aboutPanel = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(2, 2, 2, 2);
JLabel info1 = new JLabel("JCalculator");
c.gridy = 0;
aboutPanel.add(info1, c);
JLabel info2 = new JLabel("V1.2.1");
c.gridy = 1;
aboutPanel.add(info2, c);
JLabel info3 = new JLabel("Created by William Tam");
c.gridy = 2;
aboutPanel.add(info3, c);
JLabel info4 = new JLabel("2010");
c.gridy = 3;
aboutPanel.add(info4, c);
aboutFrame.add(aboutPanel);
aboutFrame.pack();
}
}
static class constantsMenuPressed implements ActionListener{
static ButtonGroup bgroup = new ButtonGroup();
public void actionPerformed(ActionEvent e){
JFrame constantsFrame = new JFrame("Constants");
constantsFrame.setVisible(true);
constantsFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
constantsFrame.setLocation(500, 0);
JRadioButton selectNumerical = new JRadioButton("Num");
selectNumerical.setMnemonic(KeyEvent.VK_N);
JRadioButton selectVariable = new JRadioButton("Var");
selectVariable.setMnemonic(KeyEvent.VK_V);
bgroup.add(selectNumerical);
bgroup.add(selectVariable);
selectVariable.setSelected(true);
//selectNumerical.addActionListener(this);
//selectVariable.addActionListener(this);
JLabel mathematicalLabel = new JLabel("Math");
JLabel physicsLabel = new JLabel("Physics");
JButton piButton = new JButton("£k");
piButton.setMargin(new Insets(2, 12, 2, 12));
piButton.addActionListener(new piConstant());
JButton eButton = new JButton("e");
eButton.setMargin(new Insets(2, 12, 2, 12));
eButton.addActionListener(new eConstant());
JButton phiButton = new JButton("£p");
phiButton.setMargin(new Insets(2, 12, 2, 12));
phiButton.addActionListener(new phiConstant());
JButton gravityButton = new JButton("g");
gravityButton.addActionListener(new gConstant());
JButton gravitationalConstantButton = new JButton("G");
gravitationalConstantButton.addActionListener(new bigGConstant());
JButton coulumbConstantButton = new JButton("k");
coulumbConstantButton.addActionListener(new kConstant());
JButton boltzmannConstantButton = new JButton("K");
boltzmannConstantButton.addActionListener(new bigKConstant());
JButton planckConstantButton = new JButton("h");
planckConstantButton.addActionListener(new hConstant());
JPanel constantsPane = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(2, 2, 2, 2);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 0;
constantsPane.add(selectVariable, c);
c.gridx = 1;
c.gridy = 0;
constantsPane.add(selectNumerical, c);
c.gridx = 0;
c.gridy = 2;
constantsPane.add(mathematicalLabel, c);
c.gridx = 2;
c.gridy = 2;
constantsPane.add(piButton, c);
c.gridx = 3;
c.gridy = 2;
constantsPane.add(eButton, c);
c.gridx = 4;
c.gridy = 2;
constantsPane.add(phiButton, c);
c.gridx = 0;
c.gridy = 4;
constantsPane.add(physicsLabel, c);
c.gridx = 2;
c.gridy = 4;
constantsPane.add(gravityButton, c);
c.gridx = 3;
c.gridy = 4;
constantsPane.add(gravitationalConstantButton, c);
c.gridx = 4;
c.gridy = 4;
constantsPane.add(coulumbConstantButton, c);
c.gridx = 5;
c.gridy = 4;
constantsPane.add(boltzmannConstantButton, c);
c.gridx = 6;
c.gridy = 4;
constantsPane.add(planckConstantButton, c);
constantsFrame.setContentPane(constantsPane);
constantsFrame.pack();
}
static class piConstant implements ActionListener{
public void actionPerformed(ActionEvent e) {
System.out.println(bgroup.getSelection().getMnemonic());
if(bgroup.getSelection().getMnemonic() == KeyEvent.VK_N)
{
CalculatorUI.input.append("" + Math.PI);
}
else if(bgroup.getSelection().getMnemonic() == KeyEvent.VK_V)
{
CalculatorUI.input.append("[pi]");
}
}
}
static class eConstant implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(bgroup.getSelection().getMnemonic() == KeyEvent.VK_N)
{
CalculatorUI.input.append("" + Math.E);
}
else if(bgroup.getSelection().getMnemonic() == KeyEvent.VK_V)
{
CalculatorUI.input.append("[e]");
}
}
}
static class phiConstant implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(bgroup.getSelection().getMnemonic() == KeyEvent.VK_N)
{
CalculatorUI.input.append("1.618033988749895");
}
else if(bgroup.getSelection().getMnemonic() == KeyEvent.VK_V)
{
CalculatorUI.input.append("[phi]");
}
}
}
static class gConstant implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(bgroup.getSelection().getMnemonic() == KeyEvent.VK_N)
{
CalculatorUI.input.append("9.80665");
}
else if(bgroup.getSelection().getMnemonic() == KeyEvent.VK_V)
{
CalculatorUI.input.append("[g]");
}
}
}
static class bigGConstant implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(bgroup.getSelection().getMnemonic() == KeyEvent.VK_N)
{
CalculatorUI.input.append("6.67428*10^(-)11");
}
else if(bgroup.getSelection().getMnemonic() == KeyEvent.VK_V)
{
CalculatorUI.input.append("[G]");
}
}
}
static class kConstant implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(bgroup.getSelection().getMnemonic() == KeyEvent.VK_N)
{
CalculatorUI.input.append("8.9875517873681764*10^9");
}
else if(bgroup.getSelection().getMnemonic() == KeyEvent.VK_V)
{
CalculatorUI.input.append("[k]");
}
}
}
static class bigKConstant implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(bgroup.getSelection().getMnemonic() == KeyEvent.VK_N)
{
CalculatorUI.input.append("1.3806504*10^(-)23");
}
else if(bgroup.getSelection().getMnemonic() == KeyEvent.VK_V)
{
CalculatorUI.input.append("[K]");
}
}
}
static class hConstant implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(bgroup.getSelection().getMnemonic() == KeyEvent.VK_N)
{
CalculatorUI.input.append("6.62606896*10^(-)34");
}
else if(bgroup.getSelection().getMnemonic() == KeyEvent.VK_V)
{
CalculatorUI.input.append("[h]");
}
}
}
}
static class trigFunctionsMenuOpened implements ActionListener{
public void actionPerformed(ActionEvent e) {
JFrame trigFunc = new JFrame("Trig Functions");
trigFunc.setVisible(true);
trigFunc.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel trigFuncPanel = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(2, 2, 2, 2);
/*
c.gridx = 0;
c.gridy = 0;
JButton sineB = new JButton("SIN");
c.gridx = 0;
c.gridy = 0;
JButton cosineB = new JButton("COS");
c.gridx = 0;
c.gridy = 0;
JButton cosecant = new JButton("TAN");
*/
c.gridx = 0;
c.gridy = 0;
JButton cosecant = new JButton("CSC");
cosecant.setMargin(new Insets(0, 6, 0, 6));
trigFuncPanel.add(cosecant, c);
c.gridx = 1;
c.gridy = 0;
JButton secant = new JButton("SEC");
secant.setMargin(new Insets(0, 6, 0, 6));
trigFuncPanel.add(secant, c);
c.gridx = 2;
c.gridy = 0;
JButton cotangent = new JButton("COT");
cotangent.setMargin(new Insets(0, 6, 0, 6));
trigFuncPanel.add(cotangent, c);
c.gridx = 0;
c.gridy = 1;
JButton arcSine = new JButton("ASIN");
arcSine.setMargin(new Insets(0, 6, 0, 6));
trigFuncPanel.add(arcSine, c);
c.gridx = 1;
c.gridy = 1;
JButton arcCosine = new JButton("ACOS");
arcCosine.setMargin(new Insets(0, 6, 0, 6));
trigFuncPanel.add(arcCosine, c);
c.gridx = 2;
c.gridy = 1;
JButton arcTangent = new JButton("ATAN");
arcTangent.setMargin(new Insets(0, 6, 0, 6));
trigFuncPanel.add(arcTangent, c);
trigFunc.setContentPane(trigFuncPanel);
trigFunc.pack();
}
}
}