jcalacc00b2
make operator buttons bright
+24 −11
1 file changed
- M src/GFrame.java +24 −11
| @@ -54,6 +54,19 @@ public class GFrame extends JFrame { | |||
| 54 | 54 | return b; | |
| 55 | 55 | } | |
| 56 | 56 | ||
| 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 | + | ||
| 57 | 70 | private void actionAdderForTextField(JButton b, String val) { | |
| 58 | 71 | b.addActionListener(new ActionListener() { | |
| 59 | 72 | public void actionPerformed(ActionEvent e) { | |
| @@ -92,16 +105,16 @@ public class GFrame extends JFrame { | |||
| 92 | 105 | this.add(lHist); | |
| 93 | 106 | ||
| 94 | 107 | // 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); | |
| 97 | 110 | JButton bClear = newButton("AC", 180, 100, 60, 40); | |
| 98 | 111 | bClear.setBackground(Color.decode("#FEA00B")); | |
| 99 | 112 | bClear.setForeground(Color.decode("#111111")); | |
| 100 | 113 | 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); | |
| 105 | 118 | JButton bCut = newButton("", 180, 300, 60, 40); | |
| 106 | 119 | bCut.setFont(new Font("JetBrainsMono Nerd Font", Font.PLAIN, 20)); | |
| 107 | 120 | JButton bRightPar = newButton(")", 110, 100, 60, 40); | |
| @@ -155,13 +168,15 @@ public class GFrame extends JFrame { | |||
| 155 | 168 | // ActionsListeners | |
| 156 | 169 | bEval.addActionListener(new ActionListener() { | |
| 157 | 170 | 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 { | |
| 160 | 175 | DecimalFormat format = new DecimalFormat(); | |
| 161 | 176 | p = new Parser(tf.getText()); | |
| 162 | 177 | String formattedResult = format.format(p.eval()); | |
| 163 | 178 | tf.setText(formattedResult); | |
| 164 | − | String formattedExpr = expression + " = " + formattedResult; | |
| 179 | + | String formattedExpr = expr + " = " + formattedResult; | |
| 165 | 180 | ||
| 166 | 181 | // Dont add to history if its already present in histList | |
| 167 | 182 | for (int i = 0; i < histList.size(); i++) { | |
| @@ -170,8 +185,6 @@ public class GFrame extends JFrame { | |||
| 170 | 185 | } | |
| 171 | 186 | } | |
| 172 | 187 | histList.addElement(formattedExpr); | |
| 173 | − | } else { | |
| 174 | − | tf.setText("No input"); | |
| 175 | 188 | } | |
| 176 | 189 | } | |
| 177 | 190 | }); | |