Compare commits

..

No commits in common. "master" and "v0.1" have entirely different histories.
master ... v0.1

6 changed files with 26 additions and 51 deletions

View File

@ -1,23 +1,16 @@
# [jcal](https://github.com/krolyxon/jcal) # [JavaCalc](https://github.com/krolyxon/JavaCalc)
Simple GUI calculator with complex infix expression evaluation made in Java using Swing. Simple GUI calculator with complex infix expression evaluation made in Java using Swing.
## Installation ## Installation
```bash ```bash
$ git clone --depth=1 https://github.com/krolyxon/jcal --branch=master $ git clone --depth=1 https://github.com/krolyxon/JavaCalc --branch=master
$ cd jcal $ cd JavaCalc
$ ./install.sh $ ./run.sh OR ./build.sh
$ jcal
``` ```
or go to latest [releases](https://github.com/krolyxon/jcal/releases) and get the .jar file.
## Uninstall ## JavaCalc in action
```bash ![](https://raw.githubusercontent.com/krolyxon/JavaCalc/master/assets/screenshot1.png)
$ ./install.sh -u
```
## jcal in action
![](https://raw.githubusercontent.com/krolyxon/jcal/master/assets/screenshot1.png)
## License ## License
This project is licensed under the [`GPLv3 LICENSE`](https://github.com/krolyxon/jcal/blob/master/LICENSE) This project is licensed under the [`GPLv3 LICENSE`](https://github.com/krolyxon/JavaCalc/blob/master/LICENSE)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/sh
mkdir -p release mkdir -p release
javac -d ./bin src/*.java javac -d ./bin src/*.java
jar cvmf manifest.mf ./release/jcal.jar -C ./bin . jar cvmf manifest.mf ./release/JavaCalc.jar -C ./bin .

View File

@ -1,10 +1,10 @@
#!/bin/sh #!/bin/sh
if [[ $* = "-u" ]] then if [[ $* = "-u" ]] then
echo "Uninstalling jcal" echo "Uninstalling JavaCalc"
echo "removing: /usr/bin/jcal.jar" echo "removing: /usr/bin/JavaCalc"
echo "removing: /usr/bin/jcal" echo "removing: /usr/bin/jcal"
sudo rm /usr/bin/jcal.jar /usr/bin/jcal sudo rm /usr/bin/JavaCalc.jar /usr/bin/jcal
else else
./build.sh ./build.sh
sudo cp ./release/*.jar /usr/bin/ sudo cp ./release/*.jar /usr/bin/

2
jcal
View File

@ -1,3 +1,3 @@
#!/bin/sh #!/bin/sh
java -jar /usr/bin/jcal.jar java -jar /usr/bin/JavaCalc.jar

View File

@ -46,24 +46,10 @@ public class GFrame extends JFrame {
// b.setBackground(Color.decode("#F78361")); // b.setBackground(Color.decode("#F78361"));
b.setBackground(Color.decode("#2B2B2B")); b.setBackground(Color.decode("#2B2B2B"));
b.setForeground(Color.decode("#e5e5e5")); b.setForeground(Color.decode("#e5e5e5"));
b.setFont((new Font("Times New Roman", 1, 20))); b.setFont((new Font("Times New Roman", Font.PLAIN, 20)));
b.setBounds(d1, d2, d3, d4); b.setBounds(d1, d2, d3, d4);
b.setBorder(new RoundBtn(15)); b.setBorder(new RoundBtn(15));
b.setText(text); b.setText(text);
b.setBorderPainted(false);
return b;
}
private JButton newButtonWhite(String text, int d1, int d2, int d3, int d4) {
JButton b = new JButton();
// b.setBackground(Color.decode("#F78361"));
b.setBackground(Color.decode("#e5e5e5"));
b.setForeground(Color.decode("#131313"));
b.setFont((new Font("Times New Roman", Font.BOLD, 20)));
b.setBounds(d1, d2, d3, d4);
b.setBorder(new RoundBtn(15));
b.setText(text);
b.setBorderPainted(false);
return b; return b;
} }
@ -99,22 +85,18 @@ private JButton newButtonWhite(String text, int d1, int d2, int d3, int d4) {
lHist.setForeground(Color.decode("#e5e5e5")); lHist.setForeground(Color.decode("#e5e5e5"));
lHist.setBounds(380, 50, 200, 240); lHist.setBounds(380, 50, 200, 240);
lHist.setFont(new Font("Times New Roman", Font.PLAIN, 20)); lHist.setFont(new Font("Times New Roman", Font.PLAIN, 20));
lHist.setSelectionBackground(Color.decode("#FEA00B")); lHist.setBorder(new RoundBtn(5));
lHist.setSelectionForeground(Color.decode("#111111"));
// lHist.setBorder(new RoundBtn(0));
this.add(lHist); this.add(lHist);
// Buttons // Buttons
JButton bEval = newButtonWhite("=", 290, 50, 60, 40); JButton bEval = newButton("=", 290, 50, 60, 40);
JButton bExp = newButtonWhite("^", 250, 100, 100, 40); JButton bExp = newButton("^", 250, 100, 100, 40);
JButton bClear = newButton("AC", 180, 100, 60, 40); JButton bClear = newButton("CL", 180, 100, 60, 40);
bClear.setBackground(Color.decode("#FEA00B"));
bClear.setForeground(Color.decode("#111111"));
JButton bClearHistory = newButton("Clear History", 380, 300, 200, 40); JButton bClearHistory = newButton("Clear History", 380, 300, 200, 40);
JButton bAdd = newButtonWhite("+", 250, 300, 100, 40); JButton bAdd = newButton("+", 250, 300, 100, 40);
JButton bSub = newButtonWhite("-", 250, 250, 100, 40); JButton bSub = newButton("-", 250, 250, 100, 40);
JButton bMul = newButtonWhite("x", 250, 200, 100, 40); JButton bMul = newButton("x", 250, 200, 100, 40);
JButton bDiv = newButtonWhite("÷", 250, 150, 100, 40); JButton bDiv = newButton("÷", 250, 150, 100, 40);
JButton bCut = newButton("", 180, 300, 60, 40); JButton bCut = newButton("", 180, 300, 60, 40);
bCut.setFont(new Font("JetBrainsMono Nerd Font", Font.PLAIN, 20)); bCut.setFont(new Font("JetBrainsMono Nerd Font", Font.PLAIN, 20));
JButton bRightPar = newButton(")", 110, 100, 60, 40); JButton bRightPar = newButton(")", 110, 100, 60, 40);
@ -168,15 +150,13 @@ private JButton newButtonWhite(String text, int d1, int d2, int d3, int d4) {
// ActionsListeners // ActionsListeners
bEval.addActionListener(new ActionListener() { bEval.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
String expr = tf.getText(); if (tf.getText().length() != 0) {
if (expr.length() == 0 || expr.equalsIgnoreCase("No input")) { String expression = tf.getText();
tf.setText("No input");
} else {
DecimalFormat format = new DecimalFormat(); DecimalFormat format = new DecimalFormat();
p = new Parser(tf.getText()); p = new Parser(tf.getText());
String formattedResult = format.format(p.eval()); String formattedResult = format.format(p.eval());
tf.setText(formattedResult); tf.setText(formattedResult);
String formattedExpr = expr + " = " + formattedResult; String formattedExpr = expression + " = " + formattedResult;
// Dont add to history if its already present in histList // Dont add to history if its already present in histList
for (int i = 0; i < histList.size(); i++) { for (int i = 0; i < histList.size(); i++) {
@ -185,6 +165,8 @@ private JButton newButtonWhite(String text, int d1, int d2, int d3, int d4) {
} }
} }
histList.addElement(formattedExpr); histList.addElement(formattedExpr);
} else {
tf.setText("No input");
} }
} }
}); });