diff --git a/src/main/java/ic/doc/RpnCalculatorGui.java b/src/main/java/ic/doc/RpnCalculatorGui.java index 9310481..3ab32b6 100644 --- a/src/main/java/ic/doc/RpnCalculatorGui.java +++ b/src/main/java/ic/doc/RpnCalculatorGui.java @@ -3,6 +3,8 @@ package ic.doc; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; +import javax.swing.JButton; +import java.util.stream.IntStream; public class RpnCalculatorGui { private final int defaultWidth; @@ -10,6 +12,10 @@ public class RpnCalculatorGui { private static final int RESULT_FIELD_WIDTH = 10; + // Define the range of numbers that can be input to the calculator + private static final int MIN_INPUT_NUMBER = 0; + private static final int MAX_INPUT_NUMBER = 9; + public static RpnCalculatorGui withDimensions(int defaultWidth, int defaultHeight) { return new RpnCalculatorGui(defaultWidth, defaultHeight); } @@ -25,6 +31,12 @@ public class RpnCalculatorGui { JPanel panel = new JPanel(); + // Add buttons for each number input + IntStream.rangeClosed(MIN_INPUT_NUMBER, MAX_INPUT_NUMBER).forEach(n -> { + JButton button = new JButton(Integer.toString(n)); + panel.add(button); + }); + JTextField resultField = new JTextField(RESULT_FIELD_WIDTH); panel.add(resultField);