From ff6d33770fd965f78a9f2a53b27900dc0e91c715 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Tue, 5 Nov 2024 17:37:07 +0000 Subject: [PATCH] Implement operator buttons for +, -, *, /, and evaluate button Co-Authored-By: td1223 --- src/main/java/ic/doc/RpnCalculatorGui.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/ic/doc/RpnCalculatorGui.java b/src/main/java/ic/doc/RpnCalculatorGui.java index 3ab32b6..f13e8d2 100644 --- a/src/main/java/ic/doc/RpnCalculatorGui.java +++ b/src/main/java/ic/doc/RpnCalculatorGui.java @@ -4,6 +4,7 @@ import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.JButton; +import java.util.Map; import java.util.stream.IntStream; public class RpnCalculatorGui { @@ -16,6 +17,13 @@ public class RpnCalculatorGui { private static final int MIN_INPUT_NUMBER = 0; private static final int MAX_INPUT_NUMBER = 9; + private static final Map operators = Map.of( + "+", new Object(), + "-", new Object(), + "*", new Object(), + "/", new Object() + ); + public static RpnCalculatorGui withDimensions(int defaultWidth, int defaultHeight) { return new RpnCalculatorGui(defaultWidth, defaultHeight); } @@ -37,9 +45,18 @@ public class RpnCalculatorGui { panel.add(button); }); + // Add buttons for each operator + operators.forEach((key, value) -> { + JButton button = new JButton(key); + panel.add(button); + }); + JTextField resultField = new JTextField(RESULT_FIELD_WIDTH); panel.add(resultField); + JButton evaluateButton = new JButton("⏎"); + panel.add(evaluateButton); + frame.add(panel); frame.setVisible(true); }