Krolyxon
Commit 17a6e45

Branches

Refs →

jcal17a6e45

fix x^n evalutation and add '^' button

Author
krolxon
Date
2024-02-17 23:35 +0530
Parent
0777aca
Commit
17a6e4575d0e94af0a4c51f209f677d61a2e59dd

+6 −3

2 files changed

  1. M src/GFrame.java +5 −2
  2. M src/Parser.java +1 −1
M src/GFrame.java View
@@ -72,7 +72,7 @@ public class GFrame extends JFrame {
7272 tf.setBackground(Color.decode("#2B2B2B"));
7373 tf.setForeground(Color.decode("#e5e5e5"));
7474 tf.setMargin(new Insets(0, 10, 0, 10));
75− tf.setBounds(40, 50, 310, 40);
75+ tf.setBounds(40, 50, 240, 40);
7676 tf.setFont((new Font("Times New Roman", Font.PLAIN, 20)));
7777 tf.setBorder(new RoundBtn(5));
7878
@@ -89,7 +89,8 @@ public class GFrame extends JFrame {
8989 tHist.setMargin(new Insets(0, 10, 0, 10));
9090
9191 // 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);
9394 JButton bClear = newButton("CL", 180, 100, 60, 40);
9495 JButton bClearHistory = newButton("Clear History", 380, 300, 200, 40);
9596 JButton bAdd = newButton("+", 250, 300, 100, 40);
@@ -113,6 +114,7 @@ public class GFrame extends JFrame {
113114 JButton bNine = newButton("9", 180, 150, 60, 40);
114115
115116 // Add the buttons to the Frame
117+ this.add(bExp);
116118 this.add(bEval);
117119 this.add(bClear);
118120 this.add(bClearHistory);
@@ -172,6 +174,7 @@ public class GFrame extends JFrame {
172174 });
173175
174176 // Common actions that just appends the symbols to the text field
177+ actionAdderForTextField(bExp, "^");
175178 actionAdderForTextField(bAdd, "+");
176179 actionAdderForTextField(bSub, "-");
177180 actionAdderForTextField(bMul, "*");
M src/Parser.java View
@@ -132,7 +132,7 @@ public class Parser {
132132 case '/':
133133 return op1 / op2;
134134 case '^':
135− return (Math.pow(op2, op1));
135+ return (Math.pow(op1, op2));
136136 default:
137137 return 0.0;
138138 }