add python like cli interface
This commit is contained in:
parent
991282cd93
commit
d987a211ff
|
|
@ -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]);
|
||||
}
|
||||
System.out.println("postfix => \t " + p.getPostfix());
|
||||
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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String> 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");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,82 @@
|
|||
public class SteelCheckBox extends javax.swing.JCheckBox
|
||||
{
|
||||
// <editor-fold defaultstate="collapsed" desc="Variable declaration">
|
||||
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";
|
||||
// </editor-fold>
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Constructor">
|
||||
public SteelCheckBox()
|
||||
{
|
||||
super();
|
||||
setPreferredSize(new java.awt.Dimension(100, 26));
|
||||
}
|
||||
// </editor-fold>
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Getter/Setter">
|
||||
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));
|
||||
}
|
||||
// </editor-fold>
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "SteelCheckBox";
|
||||
}
|
||||
}
|
||||
Reference in New Issue