Implement operator buttons for +, -, *, /, and evaluate button
Co-Authored-By: td1223
This commit is contained in:
parent
ad298f23e5
commit
ff6d33770f
|
@ -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<String, Object> 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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue