Compare commits
9 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
acc00b2470 | |
|
|
0776e6ec17 | |
|
|
7143ca3625 | |
|
|
38801f235a | |
|
|
5adf9222b2 | |
|
|
86f95482a2 | |
|
|
146590f949 | |
|
|
f6aa19d249 | |
|
|
1ce664eb6f |
21
README.md
21
README.md
|
|
@ -1,16 +1,23 @@
|
|||
# [JavaCalc](https://github.com/krolyxon/JavaCalc)
|
||||
# [jcal](https://github.com/krolyxon/jcal)
|
||||
Simple GUI calculator with complex infix expression evaluation made in Java using Swing.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ git clone --depth=1 https://github.com/krolyxon/JavaCalc --branch=master
|
||||
$ cd JavaCalc
|
||||
$ ./run.sh OR ./build.sh
|
||||
$ git clone --depth=1 https://github.com/krolyxon/jcal --branch=master
|
||||
$ cd jcal
|
||||
$ ./install.sh
|
||||
$ jcal
|
||||
```
|
||||
or go to latest [releases](https://github.com/krolyxon/jcal/releases) and get the .jar file.
|
||||
|
||||
## JavaCalc in action
|
||||

|
||||
## Uninstall
|
||||
```bash
|
||||
$ ./install.sh -u
|
||||
```
|
||||
|
||||
## jcal in action
|
||||

|
||||
|
||||
## License
|
||||
This project is licensed under the [`GPLv3 LICENSE`](https://github.com/krolyxon/JavaCalc/blob/master/LICENSE)
|
||||
This project is licensed under the [`GPLv3 LICENSE`](https://github.com/krolyxon/jcal/blob/master/LICENSE)
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 5.7 KiB |
2
build.sh
2
build.sh
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/sh
|
||||
mkdir -p release
|
||||
javac -d ./bin src/*.java
|
||||
jar cvmf manifest.mf ./release/JavaCalc.jar -C ./bin .
|
||||
jar cvmf manifest.mf ./release/jcal.jar -C ./bin .
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
#!/bin/sh
|
||||
|
||||
if [[ $* = "-u" ]] then
|
||||
echo "Uninstalling JavaCalc"
|
||||
echo "removing: /usr/bin/JavaCalc"
|
||||
echo "Uninstalling jcal"
|
||||
echo "removing: /usr/bin/jcal.jar"
|
||||
echo "removing: /usr/bin/jcal"
|
||||
sudo rm /usr/bin/JavaCalc.jar /usr/bin/jcal
|
||||
sudo rm /usr/bin/jcal.jar /usr/bin/jcal
|
||||
else
|
||||
./build.sh
|
||||
sudo cp ./release/*.jar /usr/bin/
|
||||
|
|
|
|||
2
jcal
2
jcal
|
|
@ -1,3 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
java -jar /usr/bin/JavaCalc.jar
|
||||
java -jar /usr/bin/jcal.jar
|
||||
|
|
|
|||
|
|
@ -46,10 +46,24 @@ public class GFrame extends JFrame {
|
|||
// b.setBackground(Color.decode("#F78361"));
|
||||
b.setBackground(Color.decode("#2B2B2B"));
|
||||
b.setForeground(Color.decode("#e5e5e5"));
|
||||
b.setFont((new Font("Times New Roman", Font.PLAIN, 20)));
|
||||
b.setFont((new Font("Times New Roman", 1, 20)));
|
||||
b.setBounds(d1, d2, d3, d4);
|
||||
b.setBorder(new RoundBtn(15));
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -85,18 +99,22 @@ public class GFrame extends JFrame {
|
|||
lHist.setForeground(Color.decode("#e5e5e5"));
|
||||
lHist.setBounds(380, 50, 200, 240);
|
||||
lHist.setFont(new Font("Times New Roman", Font.PLAIN, 20));
|
||||
lHist.setBorder(new RoundBtn(5));
|
||||
lHist.setSelectionBackground(Color.decode("#FEA00B"));
|
||||
lHist.setSelectionForeground(Color.decode("#111111"));
|
||||
// lHist.setBorder(new RoundBtn(0));
|
||||
this.add(lHist);
|
||||
|
||||
// Buttons
|
||||
JButton bEval = newButton("=", 290, 50, 60, 40);
|
||||
JButton bExp = newButton("^", 250, 100, 100, 40);
|
||||
JButton bClear = newButton("CL", 180, 100, 60, 40);
|
||||
JButton bEval = newButtonWhite("=", 290, 50, 60, 40);
|
||||
JButton bExp = newButtonWhite("^", 250, 100, 100, 40);
|
||||
JButton bClear = newButton("AC", 180, 100, 60, 40);
|
||||
bClear.setBackground(Color.decode("#FEA00B"));
|
||||
bClear.setForeground(Color.decode("#111111"));
|
||||
JButton bClearHistory = newButton("Clear History", 380, 300, 200, 40);
|
||||
JButton bAdd = newButton("+", 250, 300, 100, 40);
|
||||
JButton bSub = newButton("-", 250, 250, 100, 40);
|
||||
JButton bMul = newButton("x", 250, 200, 100, 40);
|
||||
JButton bDiv = newButton("÷", 250, 150, 100, 40);
|
||||
JButton bAdd = newButtonWhite("+", 250, 300, 100, 40);
|
||||
JButton bSub = newButtonWhite("-", 250, 250, 100, 40);
|
||||
JButton bMul = newButtonWhite("x", 250, 200, 100, 40);
|
||||
JButton bDiv = newButtonWhite("÷", 250, 150, 100, 40);
|
||||
JButton bCut = newButton("", 180, 300, 60, 40);
|
||||
bCut.setFont(new Font("JetBrainsMono Nerd Font", Font.PLAIN, 20));
|
||||
JButton bRightPar = newButton(")", 110, 100, 60, 40);
|
||||
|
|
@ -150,13 +168,15 @@ public class GFrame extends JFrame {
|
|||
// ActionsListeners
|
||||
bEval.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (tf.getText().length() != 0) {
|
||||
String expression = tf.getText();
|
||||
String expr = tf.getText();
|
||||
if (expr.length() == 0 || expr.equalsIgnoreCase("No input")) {
|
||||
tf.setText("No input");
|
||||
} else {
|
||||
DecimalFormat format = new DecimalFormat();
|
||||
p = new Parser(tf.getText());
|
||||
String formattedResult = format.format(p.eval());
|
||||
tf.setText(formattedResult);
|
||||
String formattedExpr = expression + " = " + formattedResult;
|
||||
String formattedExpr = expr + " = " + formattedResult;
|
||||
|
||||
// Dont add to history if its already present in histList
|
||||
for (int i = 0; i < histList.size(); i++) {
|
||||
|
|
@ -165,8 +185,6 @@ public class GFrame extends JFrame {
|
|||
}
|
||||
}
|
||||
histList.addElement(formattedExpr);
|
||||
} else {
|
||||
tf.setText("No input");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Reference in New Issue