Krolyxon
Commit d987a21

Branches

Refs →

jcald987a21

add python like cli interface

Author
krolxon
Date
2024-02-17 16:26 +0530
Parent
991282c
Commit
d987a211ff8bb0d7341bf0dddf748d8493446434

+105 −8

3 files changed

  1. M Calculator.java +22 −6
  2. M GFrame.java +1 −2
  3. A SteelCheckBox.java +82 −0
M Calculator.java View
@@ -1,14 +1,30 @@
1+import java.util.Scanner;
2+
13 public class Calculator {
24 public static void main(String[] args) {
3− GFrame frame = new GFrame("Calculator");
4− String expr = "(84 / 4 * 3 - 9) * 2 + 1 / 5"; // 108.2
5+ // String expr = "(84 / 4 * 3 - 9) * 2 + 1 / 5"; // 108.2
6+ String expr = new String(" ");
7+ Scanner sc = new Scanner(System.in);
58 Parser p;
9+
610 if (args.length == 0) {
7− p = new Parser(expr);
11+ new GFrame("Calculator");
812 } else {
9− p = new Parser(args[0]);
13+ if (args[0].equals("-n")) {
14+ System.out.println("Type \"exit\" or Ctrl+C to exit.");
15+ while (true) {
16+ System.out.print(">>> ");
17+ expr = sc.nextLine();
18+ if (!expr.equals("exit")) {
19+ p = new Parser(expr);
20+ System.out.println(p.eval());
21+ } else {
22+ sc.close();
23+ break;
24+ }
25+ }
26+ } else {
27+ }
1028 }
11− System.out.println("postfix => \t " + p.getPostfix());
12− System.out.println(p.eval());
1329 }
1430 }
M GFrame.java View
@@ -93,7 +93,7 @@ public class GFrame extends JFrame {
9393 JButton bClear = newButton("CL", 180, 100, 60, 40);
9494 JButton bAdd = newButton("+", 250, 300, 100, 40);
9595 JButton bSub = newButton("-", 250, 250, 100, 40);
96− JButton bMul = newButton("X", 250, 200, 100, 40);
96+ JButton bMul = newButton("x", 250, 200, 100, 40);
9797 JButton bDiv = newButton("%", 250, 150, 100, 40);
9898 JButton bCut = newButton("", 180, 300, 60, 40);
9999 bCut.setFont(new Font("JetBrainsMono Nerd Font", Font.PLAIN, 20));
@@ -158,7 +158,6 @@ public class GFrame extends JFrame {
158158 Vector<String> s = history.getHistory();
159159 s.add(expression + " = " + formattedResult);
160160 for (int i = 0; i < s.size(); i++) {
161− System.out.println(s.get(i));
162161 // tHist.setText(new String(s.get(i).concat(tHist.getText())).concat("\n"));
163162 tHist.append(s.get(i));
164163 tHist.append("\n");
A SteelCheckBox.java View
@@ -0,0 +1,82 @@
1+public class SteelCheckBox extends javax.swing.JCheckBox
2+{
3+ // <editor-fold defaultstate="collapsed" desc="Variable declaration">
4+ private boolean colored = false;
5+ private boolean rised = false;
6+ private eu.hansolo.tools.ColorDef selectedColor = eu.hansolo.tools.ColorDef.JUG_GREEN;
7+ protected static final String COLORED_PROPERTY = "colored";
8+ protected static final String COLOR_PROPERTY = "color";
9+ protected static final String RISED_PROPERTY = "rised";
10+ // </editor-fold>
11+
12+ // <editor-fold defaultstate="collapsed" desc="Constructor">
13+ public SteelCheckBox()
14+ {
15+ super();
16+ setPreferredSize(new java.awt.Dimension(100, 26));
17+ }
18+ // </editor-fold>
19+
20+ // <editor-fold defaultstate="collapsed" desc="Getter/Setter">
21+ public boolean isColored()
22+ {
23+ return this.colored;
24+ }
25+
26+ public void setColored(final boolean COLORED)
27+ {
28+ final boolean OLD_STATE = this.colored;
29+ this.colored = COLORED;
30+ firePropertyChange(COLORED_PROPERTY, OLD_STATE, COLORED);
31+ repaint();
32+ }
33+
34+ public boolean isRised()
35+ {
36+ return this.rised;
37+ }
38+
39+ public void setRised(final boolean RISED)
40+ {
41+ final boolean OLD_VALUE = this.rised;
42+ this.rised = RISED;
43+ firePropertyChange(RISED_PROPERTY, OLD_VALUE, RISED);
44+ }
45+
46+ public eu.hansolo.tools.ColorDef getSelectedColor()
47+ {
48+ return this.selectedColor;
49+ }
50+
51+ public void setSelectedColor(final eu.hansolo.tools.ColorDef SELECTED_COLOR)
52+ {
53+ final eu.hansolo.tools.ColorDef OLD_COLOR = this.selectedColor;
54+ this.selectedColor = SELECTED_COLOR;
55+ firePropertyChange(COLOR_PROPERTY, OLD_COLOR, SELECTED_COLOR);
56+ repaint();
57+ }
58+
59+ @Override
60+ public void setUI(final javax.swing.plaf.ButtonUI BUI)
61+ {
62+ super.setUI(new SteelCheckBoxUI(this));
63+ }
64+
65+ public void setUi(final javax.swing.plaf.ComponentUI UI)
66+ {
67+ this.ui = new SteelCheckBoxUI(this);
68+ }
69+
70+ @Override
71+ protected void setUI(final javax.swing.plaf.ComponentUI UI)
72+ {
73+ super.setUI(new SteelCheckBoxUI(this));
74+ }
75+ // </editor-fold>
76+
77+ @Override
78+ public String toString()
79+ {
80+ return "SteelCheckBox";
81+ }
82+}