Implement operator buttons for +, -, *, /, and evaluate button

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

View File

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