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.
|
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/JavaCalc --branch=master
|
$ git clone --depth=1 https://github.com/krolyxon/jcal --branch=master
|
||||||
$ cd JavaCalc
|
$ cd jcal
|
||||||
$ ./run.sh OR ./build.sh
|
$ ./install.sh
|
||||||
|
$ jcal
|
||||||
|
```
|
||||||
|
or go to latest [releases](https://github.com/krolyxon/jcal/releases) and get the .jar file.
|
||||||
|
|
||||||
|
## Uninstall
|
||||||
|
```bash
|
||||||
|
$ ./install.sh -u
|
||||||
```
|
```
|
||||||
|
|
||||||
## JavaCalc in action
|
## jcal in action
|
||||||

|

|
||||||
|
|
||||||
## License
|
## 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
|
#!/bin/sh
|
||||||
mkdir -p release
|
mkdir -p release
|
||||||
javac -d ./bin src/*.java
|
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
|
#!/bin/sh
|
||||||
|
|
||||||
if [[ $* = "-u" ]] then
|
if [[ $* = "-u" ]] then
|
||||||
echo "Uninstalling JavaCalc"
|
echo "Uninstalling jcal"
|
||||||
echo "removing: /usr/bin/JavaCalc"
|
echo "removing: /usr/bin/jcal.jar"
|
||||||
echo "removing: /usr/bin/jcal"
|
echo "removing: /usr/bin/jcal"
|
||||||
sudo rm /usr/bin/JavaCalc.jar /usr/bin/jcal
|
sudo rm /usr/bin/jcal.jar /usr/bin/jcal
|
||||||
else
|
else
|
||||||
./build.sh
|
./build.sh
|
||||||
sudo cp ./release/*.jar /usr/bin/
|
sudo cp ./release/*.jar /usr/bin/
|
||||||
|
|
|
||||||
2
jcal
2
jcal
|
|
@ -1,3 +1,3 @@
|
||||||
#!/bin/sh
|
#!/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("#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", Font.PLAIN, 20)));
|
b.setFont((new Font("Times New Roman", 1, 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,18 +99,22 @@ public class GFrame extends JFrame {
|
||||||
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.setBorder(new RoundBtn(5));
|
lHist.setSelectionBackground(Color.decode("#FEA00B"));
|
||||||
|
lHist.setSelectionForeground(Color.decode("#111111"));
|
||||||
|
// lHist.setBorder(new RoundBtn(0));
|
||||||
this.add(lHist);
|
this.add(lHist);
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
JButton bEval = newButton("=", 290, 50, 60, 40);
|
JButton bEval = newButtonWhite("=", 290, 50, 60, 40);
|
||||||
JButton bExp = newButton("^", 250, 100, 100, 40);
|
JButton bExp = newButtonWhite("^", 250, 100, 100, 40);
|
||||||
JButton bClear = newButton("CL", 180, 100, 60, 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 bClearHistory = newButton("Clear History", 380, 300, 200, 40);
|
||||||
JButton bAdd = newButton("+", 250, 300, 100, 40);
|
JButton bAdd = newButtonWhite("+", 250, 300, 100, 40);
|
||||||
JButton bSub = newButton("-", 250, 250, 100, 40);
|
JButton bSub = newButtonWhite("-", 250, 250, 100, 40);
|
||||||
JButton bMul = newButton("x", 250, 200, 100, 40);
|
JButton bMul = newButtonWhite("x", 250, 200, 100, 40);
|
||||||
JButton bDiv = newButton("÷", 250, 150, 100, 40);
|
JButton bDiv = newButtonWhite("÷", 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);
|
||||||
|
|
@ -150,13 +168,15 @@ public class GFrame extends JFrame {
|
||||||
// ActionsListeners
|
// ActionsListeners
|
||||||
bEval.addActionListener(new ActionListener() {
|
bEval.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (tf.getText().length() != 0) {
|
String expr = tf.getText();
|
||||||
String expression = tf.getText();
|
if (expr.length() == 0 || expr.equalsIgnoreCase("No input")) {
|
||||||
|
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 = expression + " = " + formattedResult;
|
String formattedExpr = expr + " = " + 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++) {
|
||||||
|
|
@ -165,8 +185,6 @@ public class GFrame extends JFrame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
histList.addElement(formattedExpr);
|
histList.addElement(formattedExpr);
|
||||||
} else {
|
|
||||||
tf.setText("No input");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Reference in New Issue