diff --git a/oysteikt-calc/src/main/java/oysteikt/calc/CalcApp.java b/oysteikt-calc/src/main/java/oysteikt/calc/CalcApp.java index 1fc4a92..d67f205 100644 --- a/oysteikt-calc/src/main/java/oysteikt/calc/CalcApp.java +++ b/oysteikt-calc/src/main/java/oysteikt/calc/CalcApp.java @@ -12,15 +12,91 @@ import java.io.IOException; * JavaFX App */ public class CalcApp extends Application { - @Override public void start(Stage stage) throws IOException { FXMLLoader fxmlLoader = new FXMLLoader(this.getClass().getResource("Calc.fxml")); Parent parent = fxmlLoader.load(); - stage.setScene(new Scene(parent)); + + /* -------------------------------------------------------------------------- */ + /* Experimental Stuff */ + /* -------------------------------------------------------------------------- */ + + CalcController controller = fxmlLoader.getController(); + Scene scene = new Scene(parent); + + this.setKeys(scene, controller); + + stage.setScene(scene); stage.show(); } + private void setKeys(Scene scene, CalcController controller) { + scene.setOnKeyTyped(e -> { + switch (e.getCharacter()) { + case ",": + case ".": + controller.handlePoint(); + break; + + case "\n": + case "\r": + controller.handleEnter(); + break; + + case "+": + controller.handleOpAdd(); + break; + + case "-": + controller.handleOpSub(); + break; + + case "*": + controller.handleOpMult(); + break; + + case "/": + case "\\": + controller.handleOpDiv(); + break; + + case "v": // Looks like a root symbol + case "r": // (R)oot + controller.handleOpRoot(); + break; + + case "~": + case "s": // (S)wap + controller.handleSwap(); + break; + + case "p": // (P)i + controller.handleOpPi(); + break; + + case "c": // (C)lear + controller.handleClear(); + break; + + case "0": + case "1": + case "2": + case "3": + case "4": + case "5": + case "6": + case "7": + case "8": + case "9": + controller.appendToOperand(e.getCharacter()); + break; + + default: + break; + } + }); + } + public static void main(String[] args) { launch(); } diff --git a/oysteikt-calc/src/main/java/oysteikt/calc/CalcController.java b/oysteikt-calc/src/main/java/oysteikt/calc/CalcController.java index dd8ad13..96da73d 100644 --- a/oysteikt-calc/src/main/java/oysteikt/calc/CalcController.java +++ b/oysteikt-calc/src/main/java/oysteikt/calc/CalcController.java @@ -78,7 +78,7 @@ public class CalcController { /* Exercise Functions */ /* -------------------------------------------------------------------------- */ - private void appendToOperand(String s) { + protected void appendToOperand(String s) { this.setOperand(this.getOperandString() + s); }