Krolyxon
Commit acc00b2

Branches

Refs →

jcalacc00b2

make operator buttons bright

Author
krolxon
Date
2024-03-03 17:31 +0530
Parent
0776e6e
Commit
acc00b2470efcddbc4ab7a48d51d3064e2976656

+24 −11

1 file changed

  1. M src/GFrame.java +24 −11
M src/GFrame.java View
@@ -54,6 +54,19 @@ public class GFrame extends JFrame {
5454 return b;
5555 }
5656
57+private JButton newButtonWhite(String text, int d1, int d2, int d3, int d4) {
58+ JButton b = new JButton();
59+ // b.setBackground(Color.decode("#F78361"));
60+ b.setBackground(Color.decode("#e5e5e5"));
61+ b.setForeground(Color.decode("#131313"));
62+ b.setFont((new Font("Times New Roman", Font.BOLD, 20)));
63+ b.setBounds(d1, d2, d3, d4);
64+ b.setBorder(new RoundBtn(15));
65+ b.setText(text);
66+ b.setBorderPainted(false);
67+ return b;
68+ }
69+
5770 private void actionAdderForTextField(JButton b, String val) {
5871 b.addActionListener(new ActionListener() {
5972 public void actionPerformed(ActionEvent e) {
@@ -92,16 +105,16 @@ public class GFrame extends JFrame {
92105 this.add(lHist);
93106
94107 // Buttons
95− JButton bEval = newButton("=", 290, 50, 60, 40);
96− JButton bExp = newButton("^", 250, 100, 100, 40);
108+ JButton bEval = newButtonWhite("=", 290, 50, 60, 40);
109+ JButton bExp = newButtonWhite("^", 250, 100, 100, 40);
97110 JButton bClear = newButton("AC", 180, 100, 60, 40);
98111 bClear.setBackground(Color.decode("#FEA00B"));
99112 bClear.setForeground(Color.decode("#111111"));
100113 JButton bClearHistory = newButton("Clear History", 380, 300, 200, 40);
101− JButton bAdd = newButton("+", 250, 300, 100, 40);
102− JButton bSub = newButton("-", 250, 250, 100, 40);
103− JButton bMul = newButton("x", 250, 200, 100, 40);
104− JButton bDiv = newButton("÷", 250, 150, 100, 40);
114+ JButton bAdd = newButtonWhite("+", 250, 300, 100, 40);
115+ JButton bSub = newButtonWhite("-", 250, 250, 100, 40);
116+ JButton bMul = newButtonWhite("x", 250, 200, 100, 40);
117+ JButton bDiv = newButtonWhite("÷", 250, 150, 100, 40);
105118 JButton bCut = newButton("", 180, 300, 60, 40);
106119 bCut.setFont(new Font("JetBrainsMono Nerd Font", Font.PLAIN, 20));
107120 JButton bRightPar = newButton(")", 110, 100, 60, 40);
@@ -155,13 +168,15 @@ public class GFrame extends JFrame {
155168 // ActionsListeners
156169 bEval.addActionListener(new ActionListener() {
157170 public void actionPerformed(ActionEvent e) {
158− if (tf.getText().length() != 0) {
159− String expression = tf.getText();
171+ String expr = tf.getText();
172+ if (expr.length() == 0 || expr.equalsIgnoreCase("No input")) {
173+ tf.setText("No input");
174+ } else {
160175 DecimalFormat format = new DecimalFormat();
161176 p = new Parser(tf.getText());
162177 String formattedResult = format.format(p.eval());
163178 tf.setText(formattedResult);
164− String formattedExpr = expression + " = " + formattedResult;
179+ String formattedExpr = expr + " = " + formattedResult;
165180
166181 // Dont add to history if its already present in histList
167182 for (int i = 0; i < histList.size(); i++) {
@@ -170,8 +185,6 @@ public class GFrame extends JFrame {
170185 }
171186 }
172187 histList.addElement(formattedExpr);
173− } else {
174− tf.setText("No input");
175188 }
176189 }
177190 });