Skip to content

Commit

Permalink
Build
Browse files Browse the repository at this point in the history
  • Loading branch information
AnanasikDev committed Apr 12, 2024
1 parent df32c2c commit b53be8a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
9 changes: 9 additions & 0 deletions .idea/artifacts/Calculator_jar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: calculator.Calculator

18 changes: 9 additions & 9 deletions src/calculator/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public void componentResized(ComponentEvent e) {
}
public void UpdateHistoryScroll(int scrollValue){
int shift = -scrollValue * historyFontSize;
if (history.getFirst().getLabel().getY() + shift > 20) return;
if (history.getLast().getLabel().getY() + shift < historyPanel.getHeight() - 20) return;
if (Utils.getFirst(history).getLabel().getY() + shift > 20) return;
if (Utils.getLast(history).getLabel().getY() + shift < historyPanel.getHeight() - 20) return;
for (HistoryToken token : history){
token.getLabel().setBounds(token.getLabel().getX(), token.getLabel().getY() + shift, token.getLabel().getWidth(), token.getLabel().getHeight());
}
Expand Down Expand Up @@ -214,47 +214,47 @@ private void adjustHistoryPanel(){
private List<CalculatorButton> getCalculatorButtons() {
List<CalculatorButton> buttons = new ArrayList<>();
buttons.add(new CalculatorButton("=", "", new Color(217, 137, 91), true));
buttons.getLast().jButton.addActionListener(new ActionListener() {
Utils.getLast(buttons).jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
evaluate();
}
});

buttons.add(new CalculatorButton("C", "", new Color(117, 117, 117), true));
buttons.getLast().jButton.addActionListener(new ActionListener() {
Utils.getLast(buttons).jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
textField.setText("");
}
});

buttons.add(new CalculatorButton("del", "", new Color(117, 117, 117), true));
buttons.getLast().jButton.addActionListener(new ActionListener() {
Utils.getLast(buttons).jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
textField.setText(textField.getText().isEmpty() ? "" : textField.getText().substring(0, textField.getText().length()-1) );
}
});

buttons.add(new CalculatorButton("ans", "", new Color(117, 117, 117), true));
buttons.getLast().jButton.addActionListener(new ActionListener() {
Utils.getLast(buttons).jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
textField.setText(textField.getText() + (history.isEmpty() ? "" : history.get(history.size()-1).getValue()));
}
});

buttons.add(new CalculatorButton("last", "", new Color(117, 117, 117), true));
buttons.getLast().jButton.addActionListener(new ActionListener() {
Utils.getLast(buttons).jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
textField.setText(textField.getText() + (history.isEmpty() ? "" : history.get(history.size()-1).getExpression()));
}
});

buttons.add(new CalculatorButton(solver.degMod ? "deg" : "rad", "", new Color(117, 117, 117), true));
buttons.getLast().jButton.addActionListener(new ActionListener() {
Utils.getLast(buttons).jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
solver.setDegMod(!solver.degMod);
Expand Down Expand Up @@ -283,7 +283,7 @@ public void actionPerformed(ActionEvent e) {
buttons.add(new CalculatorButton(".", ".", new Color(135, 222, 184)));
buttons.add(new CalculatorButton("0", "0", new Color(135, 222, 184)));
buttons.add(new CalculatorButton("-", "", new Color(135, 222, 184), true));
buttons.getLast().jButton.addActionListener(new ActionListener() {
Utils.getLast(buttons).jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
textField.setText("-(" + textField.getText() + ")");
Expand Down
19 changes: 19 additions & 0 deletions src/calculator/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package calculator;

import java.util.ArrayList;
import java.util.List;

public class Utils {
public static <T> T getFirst(ArrayList<T> list){
return list.get(0);
}
public static <T> T getLast(ArrayList<T> list){
return list.get(list.size() - 1);
}
public static <T> T getFirst(List<T> list){
return list.get(0);
}
public static <T> T getLast(List<T> list){
return list.get(list.size() - 1);
}
}

0 comments on commit b53be8a

Please sign in to comment.