From b53be8ae58df78dbd78494719745d7b6186322fb Mon Sep 17 00:00:00 2001 From: oleg Date: Fri, 12 Apr 2024 12:25:51 +0200 Subject: [PATCH] Build --- .idea/artifacts/Calculator_jar.xml | 9 +++++++++ .idea/gradle.xml | 4 ++++ .idea/misc.xml | 3 ++- src/META-INF/MANIFEST.MF | 3 +++ src/calculator/Calculator.java | 18 +++++++++--------- src/calculator/Utils.java | 19 +++++++++++++++++++ 6 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 .idea/artifacts/Calculator_jar.xml create mode 100644 .idea/gradle.xml create mode 100644 src/META-INF/MANIFEST.MF create mode 100644 src/calculator/Utils.java diff --git a/.idea/artifacts/Calculator_jar.xml b/.idea/artifacts/Calculator_jar.xml new file mode 100644 index 0000000..849002b --- /dev/null +++ b/.idea/artifacts/Calculator_jar.xml @@ -0,0 +1,9 @@ + + + $PROJECT_DIR$/out/artifacts/Calculator_jar + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..3e3960b --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 4444b22..43b1638 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,7 @@ - + + \ No newline at end of file diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..9aa4654 --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: calculator.Calculator + diff --git a/src/calculator/Calculator.java b/src/calculator/Calculator.java index 839cd15..2fccfb9 100644 --- a/src/calculator/Calculator.java +++ b/src/calculator/Calculator.java @@ -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()); } @@ -214,7 +214,7 @@ private void adjustHistoryPanel(){ private List getCalculatorButtons() { List 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(); @@ -222,7 +222,7 @@ public void actionPerformed(ActionEvent e) { }); 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(""); @@ -230,7 +230,7 @@ public void actionPerformed(ActionEvent e) { }); 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) ); @@ -238,7 +238,7 @@ public void actionPerformed(ActionEvent e) { }); 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())); @@ -246,7 +246,7 @@ public void actionPerformed(ActionEvent e) { }); 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())); @@ -254,7 +254,7 @@ public void actionPerformed(ActionEvent e) { }); 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); @@ -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() + ")"); diff --git a/src/calculator/Utils.java b/src/calculator/Utils.java new file mode 100644 index 0000000..5c69f82 --- /dev/null +++ b/src/calculator/Utils.java @@ -0,0 +1,19 @@ +package calculator; + +import java.util.ArrayList; +import java.util.List; + +public class Utils { + public static T getFirst(ArrayList list){ + return list.get(0); + } + public static T getLast(ArrayList list){ + return list.get(list.size() - 1); + } + public static T getFirst(List list){ + return list.get(0); + } + public static T getLast(List list){ + return list.get(list.size() - 1); + } +}