Add number inputs from 0 to 9 to GUI

Co-Authored-By: td1223
This commit is contained in:
Gleb Koval 2024-11-05 17:29:35 +00:00
parent 45a06ab15e
commit ad298f23e5
Signed by: cyclane
GPG Key ID: 15E168A8B332382C
1 changed files with 12 additions and 0 deletions

View File

@ -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);