Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package corseworkerino;
- import java.io.IOException;
- import java.util.function.Consumer;
- import javafx.application.Application;
- import javafx.beans.value.ChangeListener;
- import javafx.beans.value.ObservableValue;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.fxml.FXML;
- import javafx.fxml.FXMLLoader;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.RadioButton;
- import javafx.scene.control.TextField;
- import javafx.scene.control.Toggle;
- import javafx.scene.control.ToggleGroup;
- import javafx.scene.layout.GridPane;
- import javafx.stage.Stage;
- public class CalcView extends Application implements ViewInterface {
- @FXML
- // fx:id="calcButton"
- private Button calcButton; // Value injected by FXMLLoader
- @FXML
- // fx:id="infixButton"
- private RadioButton infixButton; // Value injected by FXMLLoader
- @FXML
- // fx:id="type"
- private ToggleGroup type; // Value injected by FXMLLoader
- @FXML
- // fx:id="postfixButton"
- private RadioButton postfixButton; // Value injected by FXMLLoader
- @FXML
- // fx:id="question"
- private TextField question; // Value injected by FXMLLoader
- @FXML
- // fx:id="answer"
- private Label answer; // Value injected by FXMLLoader
- /////////////////////////////////////////////////////////////////////////////////
- // Block for creating an instance variable for others to use.
- //
- // Make it a JavaFX singleton. Instance is set by the javafx "initialize" method
- private volatile static CalcView instance = null;
- @FXML
- void initialize() {
- instance = this;
- }
- public synchronized static CalcView getInstance() {
- if (instance == null) {
- new Thread(() -> Application.launch(CalcView.class)).start();
- // Wait until the instance is ready since initialize has executed.
- while (instance == null) {// empty body
- }
- }
- return instance;
- }
- // End of special block
- /////////////////////////////////////////////////////////////////////////////////
- @Override
- public void start(Stage primaryStage) throws IOException {
- GridPane page = (GridPane) FXMLLoader.load(CalcView.class
- .getResource("CalcView.fxml"));
- Scene scene = new Scene(page);
- scene.getStylesheets().add(
- getClass().getResource("application.css").toExternalForm());
- primaryStage.setScene(scene);
- primaryStage.setTitle("MVC with JavaFX and FXML");
- primaryStage.show();
- }
- @Override
- public void addCalcObserver(Observer f) {
- calcButton.setOnAction(event -> f.tell());
- }
- @Override
- public void addTypeObserver(Observer f) {
- infixButton.setOnAction(event -> f.tell());
- postfixButton.setOnAction(event -> f.tell());
- }
- @Override
- public OpType getType() {
- if (postfixButton.isSelected()) {
- return OpType.POSTFIX;
- }else {
- return OpType.INFIX;
- }
- }
- @Override
- public String getQuestion() {
- return question.getText();
- }
- @Override
- public void setAnswer(String a) {
- answer.setText(a);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement