diff --git a/Calculator.java b/Calculator.java index 7070c87..c43ca9f 100644 --- a/Calculator.java +++ b/Calculator.java @@ -1,14 +1,30 @@ +import java.util.Scanner; + public class Calculator { public static void main(String[] args) { - GFrame frame = new GFrame("Calculator"); - String expr = "(84 / 4 * 3 - 9) * 2 + 1 / 5"; // 108.2 + // String expr = "(84 / 4 * 3 - 9) * 2 + 1 / 5"; // 108.2 + String expr = new String(" "); + Scanner sc = new Scanner(System.in); Parser p; + if (args.length == 0) { - p = new Parser(expr); + new GFrame("Calculator"); } else { - p = new Parser(args[0]); + if (args[0].equals("-n")) { + System.out.println("Type \"exit\" or Ctrl+C to exit."); + while (true) { + System.out.print(">>> "); + expr = sc.nextLine(); + if (!expr.equals("exit")) { + p = new Parser(expr); + System.out.println(p.eval()); + } else { + sc.close(); + break; + } + } + } else { + } } - System.out.println("postfix => \t " + p.getPostfix()); - System.out.println(p.eval()); } } diff --git a/GFrame.java b/GFrame.java index 4ba0a82..14feb30 100644 --- a/GFrame.java +++ b/GFrame.java @@ -93,7 +93,7 @@ public class GFrame extends JFrame { JButton bClear = newButton("CL", 180, 100, 60, 40); JButton bAdd = newButton("+", 250, 300, 100, 40); JButton bSub = newButton("-", 250, 250, 100, 40); - JButton bMul = newButton("X", 250, 200, 100, 40); + JButton bMul = newButton("x", 250, 200, 100, 40); JButton bDiv = newButton("%", 250, 150, 100, 40); JButton bCut = newButton("", 180, 300, 60, 40); bCut.setFont(new Font("JetBrainsMono Nerd Font", Font.PLAIN, 20)); @@ -158,7 +158,6 @@ public class GFrame extends JFrame { Vector s = history.getHistory(); s.add(expression + " = " + formattedResult); for (int i = 0; i < s.size(); i++) { - System.out.println(s.get(i)); // tHist.setText(new String(s.get(i).concat(tHist.getText())).concat("\n")); tHist.append(s.get(i)); tHist.append("\n"); diff --git a/SteelCheckBox.java b/SteelCheckBox.java new file mode 100644 index 0000000..6732c26 --- /dev/null +++ b/SteelCheckBox.java @@ -0,0 +1,82 @@ +public class SteelCheckBox extends javax.swing.JCheckBox +{ + // + private boolean colored = false; + private boolean rised = false; + private eu.hansolo.tools.ColorDef selectedColor = eu.hansolo.tools.ColorDef.JUG_GREEN; + protected static final String COLORED_PROPERTY = "colored"; + protected static final String COLOR_PROPERTY = "color"; + protected static final String RISED_PROPERTY = "rised"; + // + + // + public SteelCheckBox() + { + super(); + setPreferredSize(new java.awt.Dimension(100, 26)); + } + // + + // + public boolean isColored() + { + return this.colored; + } + + public void setColored(final boolean COLORED) + { + final boolean OLD_STATE = this.colored; + this.colored = COLORED; + firePropertyChange(COLORED_PROPERTY, OLD_STATE, COLORED); + repaint(); + } + + public boolean isRised() + { + return this.rised; + } + + public void setRised(final boolean RISED) + { + final boolean OLD_VALUE = this.rised; + this.rised = RISED; + firePropertyChange(RISED_PROPERTY, OLD_VALUE, RISED); + } + + public eu.hansolo.tools.ColorDef getSelectedColor() + { + return this.selectedColor; + } + + public void setSelectedColor(final eu.hansolo.tools.ColorDef SELECTED_COLOR) + { + final eu.hansolo.tools.ColorDef OLD_COLOR = this.selectedColor; + this.selectedColor = SELECTED_COLOR; + firePropertyChange(COLOR_PROPERTY, OLD_COLOR, SELECTED_COLOR); + repaint(); + } + + @Override + public void setUI(final javax.swing.plaf.ButtonUI BUI) + { + super.setUI(new SteelCheckBoxUI(this)); + } + + public void setUi(final javax.swing.plaf.ComponentUI UI) + { + this.ui = new SteelCheckBoxUI(this); + } + + @Override + protected void setUI(final javax.swing.plaf.ComponentUI UI) + { + super.setUI(new SteelCheckBoxUI(this)); + } + // + + @Override + public String toString() + { + return "SteelCheckBox"; + } +}