Add number inputs from 0 to 9 to GUI
Co-Authored-By: td1223
This commit is contained in:
parent
45a06ab15e
commit
ad298f23e5
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue