jcal17a6e45
fix x^n evalutation and add '^' button
+6 −3
2 files changed
- M src/GFrame.java +5 −2
- M src/Parser.java +1 −1
| @@ -72,7 +72,7 @@ public class GFrame extends JFrame { | |||
| 72 | 72 | tf.setBackground(Color.decode("#2B2B2B")); | |
| 73 | 73 | tf.setForeground(Color.decode("#e5e5e5")); | |
| 74 | 74 | tf.setMargin(new Insets(0, 10, 0, 10)); | |
| 75 | − | tf.setBounds(40, 50, 310, 40); | |
| 75 | + | tf.setBounds(40, 50, 240, 40); | |
| 76 | 76 | tf.setFont((new Font("Times New Roman", Font.PLAIN, 20))); | |
| 77 | 77 | tf.setBorder(new RoundBtn(5)); | |
| 78 | 78 | ||
| @@ -89,7 +89,8 @@ public class GFrame extends JFrame { | |||
| 89 | 89 | tHist.setMargin(new Insets(0, 10, 0, 10)); | |
| 90 | 90 | ||
| 91 | 91 | // Buttons | |
| 92 | − | JButton bEval = newButton("=", 250, 100, 100, 40); | |
| 92 | + | JButton bEval= newButton("=", 290, 50, 60, 40); | |
| 93 | + | JButton bExp= newButton("^", 250, 100, 100, 40); | |
| 93 | 94 | JButton bClear = newButton("CL", 180, 100, 60, 40); | |
| 94 | 95 | JButton bClearHistory = newButton("Clear History", 380, 300, 200, 40); | |
| 95 | 96 | JButton bAdd = newButton("+", 250, 300, 100, 40); | |
| @@ -113,6 +114,7 @@ public class GFrame extends JFrame { | |||
| 113 | 114 | JButton bNine = newButton("9", 180, 150, 60, 40); | |
| 114 | 115 | ||
| 115 | 116 | // Add the buttons to the Frame | |
| 117 | + | this.add(bExp); | |
| 116 | 118 | this.add(bEval); | |
| 117 | 119 | this.add(bClear); | |
| 118 | 120 | this.add(bClearHistory); | |
| @@ -172,6 +174,7 @@ public class GFrame extends JFrame { | |||
| 172 | 174 | }); | |
| 173 | 175 | ||
| 174 | 176 | // Common actions that just appends the symbols to the text field | |
| 177 | + | actionAdderForTextField(bExp, "^"); | |
| 175 | 178 | actionAdderForTextField(bAdd, "+"); | |
| 176 | 179 | actionAdderForTextField(bSub, "-"); | |
| 177 | 180 | actionAdderForTextField(bMul, "*"); | |
| @@ -132,7 +132,7 @@ public class Parser { | |||
| 132 | 132 | case '/': | |
| 133 | 133 | return op1 / op2; | |
| 134 | 134 | case '^': | |
| 135 | − | return (Math.pow(op2, op1)); | |
| 135 | + | return (Math.pow(op1, op2)); | |
| 136 | 136 | default: | |
| 137 | 137 | return 0.0; | |
| 138 | 138 | } | |