/************************************************** * Author: Morrison * Date: 12 Apr 202021 **************************************************/ import javafx.application.Application; import javafx.application.Platform; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.TextField; import javafx.scene.layout.BorderPane; import javafx.scene.layout.GridPane; public class RPN extends Application { private final TextField display; private NumberButton[] digits; private NumberButton decimalPoint; private NumberButton exponent; private Button clearButton; Button clearEntryButton; Button enterButton; public RPN() { display = new TextField(); digits = new NumberButton[10]; for(int k = 0; k < 10; k++) { digits[k] = new NumberButton((char)(0x30 + k)); } decimalPoint = new NumberButton('.'); clearButton = new Button("C"); clearEntryButton = new Button("CE"); enterButton = new Button("ENTER"); exponent = new NumberButton('E'); } @Override public void init() { } @Override public void start(Stage primary) { BorderPane bp = new BorderPane(); GridPane gp = new GridPane(); gp.add(digits[7], 0, 0); gp.add(digits[8], 1, 0); gp.add(digits[9], 2, 0); gp.add(digits[4], 0, 1); gp.add(digits[5], 1, 1); gp.add(digits[6], 2, 1); gp.add(digits[1], 0, 2); gp.add(digits[2], 1, 2); gp.add(digits[3], 2, 2); gp.add(decimalPoint, 0, 3); gp.add(digits[0], 1, 3); gp.add(exponent, 2, 3); bp.setTop(display); bp.setCenter(gp); primary.setScene(new Scene(bp, 700, 500)); primary.show(); } @Override public void stop() { } /********************** Inner Classes ********************/ class NumberButton extends Button { private final char num; public NumberButton(char num) { super("" + num); this.num = num; setOnAction( e -> { display.setText(display.getText() + num); }); } } class OpButton extends Button { } class FunctionButton extends Button { } }