public void start(Stage stage) { Button yesButton = new Button("Yes"); Button noButton = new Button("No"); Button maybeButton = new Button("Maybe"); final double rem = Font.getDefault().getSize(); HBox buttons = new HBox(0.8 * rem); buttons.getChildren().addAll(yesButton, noButton, maybeButton); VBox pane = new VBox(0.8 * rem); Label question = new Label("Will you attend?"); pane.setPadding(new Insets(0.8 * rem)); pane.getChildren().addAll(question, buttons); stage.setScene(new Scene(pane)); stage.show(); }
private void updateSelectedEntry() { ObservableList<PolizistDaten> Nutzerauswahl = Tabelle.getSelectionModel().getSelectedItems(); if (Nutzerauswahl.size() != 1) { IM.setErrorText("Es muss genau ein Element ausgewählt werden"); return; } PolizistDaten Auswahl = Nutzerauswahl.get(0); // Jetzt erzeugen wir ein PopUp zum veraendern des Eintrags Stage PopUp = new Stage(); PopUp.initModality(Modality.APPLICATION_MODAL); PopUp.setTitle("Neuer Eintrag"); PopUp.setAlwaysOnTop(true); PopUp.setResizable(false); GridPane Gitter = new GridPane(); Gitter.setHgap(10); Gitter.setVgap(10); Label LabelA = new Label("PersonenID"); Label LabelAWert = new Label(Integer.toString(Auswahl.getPersonenID())); Label LabelB = new Label("Name"); TextField LabelBWert = new TextField(); Label LabelC = new Label("Geburtsdatum"); DatePicker LabelCWert = new DatePicker(); Label LabelD = new Label("Nationalität"); TextField LabelDWert = new TextField(); Label LabelE = new Label("Geschlecht"); ComboBox LabelEWert = new ComboBox(); Label LabelF = new Label("Todesdatum"); DatePicker LabelFWert = new DatePicker(); Label LabelG = new Label("Dienstgrad"); TextField LabelGWert = new TextField(); final Callback<DatePicker, DateCell> TagesZellenFabtrik = new Callback<DatePicker, DateCell>() { @Override public DateCell call(final DatePicker DP) { return new DateCell() { @Override public void updateItem(LocalDate item, boolean empty) { super.updateItem(item, empty); if (item.isBefore(LabelCWert.getValue().plusDays(1))) { setDisable(true); setStyle("-fx-background-color: #ffc0cb;"); } } }; } }; LabelFWert.setDayCellFactory(TagesZellenFabtrik); LabelEWert.getItems().addAll("m", "w"); LabelEWert.setValue(Auswahl.getGeschlecht()); LabelBWert.setText(Auswahl.getName()); LabelCWert.setValue(LocalDate.parse(Auswahl.getGebDatum())); // TODO exception LabelDWert.setText(Auswahl.getNation()); if (!Auswahl.getTodDatum().isEmpty()) { LabelFWert.setValue(LocalDate.parse(Auswahl.getTodDatum())); // TODO exception } LabelGWert.setText(Auswahl.getDienstgrad()); Button ButtonFort = new Button("Fortfahren"); Button ButtonAbb = new Button("Abbrechen"); ButtonFort.defaultButtonProperty(); ButtonAbb.cancelButtonProperty(); ButtonFort.setMaxWidth(Double.MAX_VALUE); ButtonAbb.setMaxWidth(Double.MAX_VALUE); Gitter.addColumn(0, LabelA, LabelB, LabelC, LabelD, LabelE, LabelF, LabelG); Gitter.addColumn( 1, LabelAWert, LabelBWert, LabelCWert, LabelDWert, LabelEWert, LabelFWert, LabelGWert); VBox AussenBox = new VBox(10); HBox InnenBox = new HBox(); AussenBox.setSpacing(10); AussenBox.setPadding(new Insets(10)); InnenBox.setSpacing(10); AussenBox.setAlignment(Pos.CENTER); InnenBox.setAlignment(Pos.BOTTOM_CENTER); AussenBox.getChildren().addAll(Gitter, InnenBox); InnenBox.getChildren().addAll(ButtonFort, ButtonAbb); ButtonAbb.setOnAction(event -> PopUp.close()); ButtonFort.setOnAction( event -> { String SQLString; if (LabelFWert.getEditor().getText().isEmpty()) { SQLString = "UPDATE PERSON SET Name=?, Geburtsdatum=?, Nationalität=?, Geschlecht=?, Todesdatum=NULL WHERE PersonenID = " + Auswahl.getPersonenID(); } else { SQLString = "UPDATE PERSON SET Name=?, Geburtsdatum=?, Nationalität=?, Geschlecht=?, Todesdatum=? WHERE PersonenID = " + Auswahl.getPersonenID(); } try { PreparedStatement InsertStatement = DH.prepareStatement(SQLString); InsertStatement.setString(1, LabelBWert.getText()); InsertStatement.setString(2, LabelCWert.getValue().toString()); // TODO exception InsertStatement.setString(3, LabelDWert.getText()); InsertStatement.setString(4, LabelEWert.getValue().toString()); if (LabelFWert.getValue() != null && !LabelFWert.getEditor().getText().isEmpty()) { InsertStatement.setString(5, LabelFWert.getValue().toString()); } InsertStatement.executeUpdate(); SQLString = "UPDATE POLIZIST SET Dienstgrad = ? WHERE PersonenID = " + Auswahl.getPersonenID(); InsertStatement = DH.prepareStatement(SQLString); InsertStatement.setString(1, LabelGWert.getText()); InsertStatement.execute(); IM.setInfoText("Änderung durchgeführt"); } catch (SQLException e) { IM.setErrorText("Ändern Fehlgeschlagen", e); } refreshPolizistAnsicht(); PopUp.close(); }); PopUp.setScene(new Scene(AussenBox)); PopUp.showAndWait(); }
private void erzeugeDetailAnsicht(PolizistDaten SpaltenDaten) { Label LabelA = new Label("PersonenID"); Label LabelAWert = new Label(Integer.toString(SpaltenDaten.getPersonenID())); Label LabelB = new Label("Name"); Label LabelBWert = new Label(SpaltenDaten.getName()); Label LabelC = new Label("Geburtsdatum"); Label LabelCWert = new Label(SpaltenDaten.getGebDatum()); Label LabelD = new Label("Nationalität"); Label LabelDWert = new Label(SpaltenDaten.getNation()); Label LabelE = new Label("Geschlecht"); Label LabelEWert = new Label(SpaltenDaten.getGeschlecht()); Label LabelF = new Label("Todesdatum"); Label LabelFWert = new Label(SpaltenDaten.getTodDatum()); Label LabelG = new Label("Dienstgrad"); Label LabelGWert = new Label(SpaltenDaten.getDienstgrad()); Button ButtonBearbeiten = new Button("Bearbeiten..."); Button ButtonLoeschen = new Button("Löschen"); Button ButtonSuchePerson = new Button("Suche nach Person"); Button ButtonSucheArbeit = new Button("Suche nach Arbeitsverhältnissen"); Button ButtonSucheArbeitAn = new Button("Suche nach zugewiesenen Fällen"); Button ButtonSucheNotizen = new Button("Suche nach erstellten Notizen"); Button ButtonSucheIndizien = new Button("Suche nach eingestellten Indizien"); Button ButtonClose = new Button("Detailansicht verlassen"); ButtonBearbeiten.setOnAction( event -> { Tabelle.getSelectionModel().clearSelection(); Tabelle.getSelectionModel().select(SpaltenDaten); updateSelectedEntry(); Hauptprogramm.setRechteAnsicht(null); }); ButtonLoeschen.setOnAction( event -> { Tabelle.getSelectionModel().clearSelection(); Tabelle.getSelectionModel().select(SpaltenDaten); deleteSelectedEntrys(); Hauptprogramm.setRechteAnsicht(null); }); ButtonSuchePerson.setOnAction( event -> { Hauptprogramm.setRechteAnsicht(null); PersonenAM.PersonenSuchAnsicht(SpaltenDaten.getPersonenID()); }); ButtonSucheArbeit.setOnAction( event -> { Hauptprogramm.setRechteAnsicht(null); ArbeitenAM.SucheNachPersonenID(SpaltenDaten.getPersonenID()); }); ButtonSucheArbeitAn.setOnAction( event -> { Hauptprogramm.setRechteAnsicht(null); ArbeitenAnAM.SucheNachPersonenID(SpaltenDaten.getPersonenID()); }); ButtonSucheNotizen.setOnAction( event -> { Hauptprogramm.setRechteAnsicht(null); NotizAM.SucheNachAnlegendem(SpaltenDaten.getPersonenID()); }); ButtonSucheIndizien.setOnAction( event -> { Hauptprogramm.setRechteAnsicht(null); IndizAM.SucheNachAnlegendem(SpaltenDaten.getPersonenID()); }); ButtonClose.setOnAction(event -> Hauptprogramm.setRechteAnsicht(null)); ButtonBearbeiten.setMaxWidth(Double.MAX_VALUE); ButtonBearbeiten.setMinWidth(150); ButtonLoeschen.setMaxWidth(Double.MAX_VALUE); ButtonLoeschen.setMinWidth(150); ButtonSuchePerson.setMaxWidth(Double.MAX_VALUE); ButtonSucheArbeit.setMaxWidth(Double.MAX_VALUE); ButtonSucheArbeitAn.setMaxWidth(Double.MAX_VALUE); ButtonSucheNotizen.setMaxWidth(Double.MAX_VALUE); ButtonSucheIndizien.setMaxWidth(Double.MAX_VALUE); ButtonClose.setMaxWidth(Double.MAX_VALUE); // Wir haben ein Gridpane oben, eine HBox unten in einer VBox in einem ScrollPane GridPane Oben = new GridPane(); Oben.setHgap(10); Oben.setVgap(10); Oben.addColumn(0, LabelA, LabelB, LabelC, LabelD, LabelE, LabelF, LabelG); Oben.addColumn( 1, LabelAWert, LabelBWert, LabelCWert, LabelDWert, LabelEWert, LabelFWert, LabelGWert); Oben.getColumnConstraints().add(new ColumnConstraints(100)); Oben.getColumnConstraints().add(new ColumnConstraints(200)); HBox Unten = new HBox(10); Unten.getChildren().addAll(ButtonBearbeiten, ButtonLoeschen); Unten.setMaxWidth(300); Unten.alignmentProperty().setValue(Pos.CENTER); VBox Mittelteil = new VBox(10); Mittelteil.setPadding(new Insets(10, 20, 10, 10)); Mittelteil.getChildren() .addAll( Oben, Unten, ButtonSuchePerson, ButtonSucheArbeit, ButtonSucheArbeitAn, ButtonSucheNotizen, ButtonSucheIndizien, ButtonClose); ScrollPane Aussen = new ScrollPane(); Aussen.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); Aussen.setContent(Mittelteil); Hauptprogramm.setRechteAnsicht(Aussen); }
private void insertNewEntry() { Stage PopUp = new Stage(); PopUp.initModality(Modality.APPLICATION_MODAL); PopUp.setTitle("Neuer Eintrag"); PopUp.setAlwaysOnTop(true); PopUp.setResizable(false); GridPane Gitter = new GridPane(); Gitter.setHgap(10); Gitter.setVgap(10); Label LabelB = new Label("Name"); TextField LabelBWert = new TextField(); Label LabelC = new Label("Geburtsdatum"); DatePicker LabelCWert = new DatePicker(); Label LabelD = new Label("Nationalität"); TextField LabelDWert = new TextField(); Label LabelE = new Label("Geschlecht"); ComboBox LabelEWert = new ComboBox(); Label LabelF = new Label("Todesdatum"); DatePicker LabelFWert = new DatePicker(); Label LabelG = new Label("Dienstgrad"); TextField LabelGWert = new TextField(); final Callback<DatePicker, DateCell> TagesZellenFabtrik = new Callback<DatePicker, DateCell>() { @Override public DateCell call(final DatePicker DP) { return new DateCell() { @Override public void updateItem(LocalDate item, boolean empty) { super.updateItem(item, empty); if (item.isBefore(LabelCWert.getValue().plusDays(1))) { setDisable(true); setStyle("-fx-background-color: #ffc0cb;"); } } }; } }; LabelFWert.setDayCellFactory(TagesZellenFabtrik); LabelEWert.getItems().addAll("m", "w"); LabelEWert.setValue("m"); Button ButtonFort = new Button("Fortfahren"); Button ButtonAbb = new Button("Abbrechen"); ButtonFort.defaultButtonProperty(); ButtonAbb.cancelButtonProperty(); ButtonFort.setMaxWidth(Double.MAX_VALUE); ButtonAbb.setMaxWidth(Double.MAX_VALUE); Gitter.addColumn(0, LabelB, LabelC, LabelD, LabelE, LabelF, LabelG); Gitter.addColumn(1, LabelBWert, LabelCWert, LabelDWert, LabelEWert, LabelFWert, LabelGWert); VBox AussenBox = new VBox(10); HBox InnenBox = new HBox(); AussenBox.setSpacing(10); AussenBox.setPadding(new Insets(10)); InnenBox.setSpacing(10); AussenBox.setAlignment(Pos.CENTER); InnenBox.setAlignment(Pos.BOTTOM_CENTER); AussenBox.getChildren().addAll(Gitter, InnenBox); InnenBox.getChildren().addAll(ButtonFort, ButtonAbb); ButtonAbb.setOnAction(event -> PopUp.close()); ButtonFort.setOnAction( event -> { String SQLString; if (LabelFWert.getValue() != null) { SQLString = "INSERT INTO PERSON (Name, Geburtsdatum, Nationalität, Geschlecht, Todesdatum) VALUES (?, ?, ?, ?, ?)"; } else { SQLString = "INSERT INTO PERSON (Name, Geburtsdatum, Nationalität, Geschlecht) VALUES (?, ?, ?, ?)"; } try { PreparedStatement InsertStatement = DH.prepareStatement(SQLString); InsertStatement.setString(1, LabelBWert.getText()); InsertStatement.setString(2, LabelCWert.getValue().toString()); // TODO exception InsertStatement.setString(3, LabelDWert.getText()); InsertStatement.setString(4, LabelEWert.getValue().toString()); if (LabelFWert.getValue() != null) { InsertStatement.setString(5, LabelFWert.getValue().toString()); // TODO exception } InsertStatement.executeUpdate(); ResultSet PersID = DH.getAnfrageObjekt().executeQuery("SELECT last_insert_rowid();"); if (!PersID.next()) { IM.setErrorText("Konnte Primärschlüssel nicht mehr bestimmen."); } SQLString = "INSERT INTO POLIZIST (PersonenID, Dienstgrad) VALUES (?, ?)"; InsertStatement = DH.prepareStatement(SQLString); InsertStatement.setInt(1, PersID.getInt(1)); // TODO das hier verifizieren InsertStatement.setString(2, LabelGWert.getText()); InsertStatement.executeUpdate(); IM.setInfoText("Einfügen durchgeführt"); } catch (SQLException e) { IM.setErrorText("Einfügen Fehlgeschlagen", e); } refreshPolizistAnsicht(); PopUp.close(); }); PopUp.setScene(new Scene(AussenBox)); PopUp.showAndWait(); }
/** * Draws the MapMaker screen and displays it to the user * * @param primaryStage the stage to show it in * @throws Exception */ public void drawScreen(Stage primaryStage) throws Exception { // Create the base BorderPane for the whole window BorderPane borderPane = new BorderPane(); borderPane.setStyle("-fx-background-color: papayawhip"); // Add some instructions to the user String text = "Instructions:\n" + "1. Click on the map component that you would like to place in the map\n" + "2. Click on the place in the map where you want to place the component\n" + "3. Repeat until you built the map you want!\n" + "4. Hit the 'Save' button when you are done"; Label instructions = new Label(text); instructions.setFont(Font.font("Arial", FontWeight.BOLD, 12)); instructions.setPadding(new Insets(5, 5, 5, 5)); borderPane.setTop(instructions); // Create the blank Map Pane mapPane = new Pane(); Map map = new Map(width, height); MapGridGUIDecorator mapGridGUIDecorator = new MapGridGUIDecorator(map.getGrid()); ResizeFactor rf = ResizeFactor.getSuggestedResizeFactor(width, height); mapGridGUIDecorator.setResizeFactor(rf); GridPane mapGridPane = mapGridGUIDecorator.drawComponents(); mapGridPane.setPadding(new Insets(0, 0, 5, 5)); mapPane.getChildren().add(mapGridPane); borderPane.setCenter(mapPane); MapMakerController.setCurrentFocused(ComponentType.NOTHING); VBox sideComponents = new VBox(); /* Add "Components" label */ Label componentsLabel = new Label("Components"); componentsLabel.setFont(Font.font("Arial", FontWeight.EXTRA_BOLD, 14)); componentsLabel.setPadding(new Insets(15, 5, 0, 20)); sideComponents.getChildren().add(componentsLabel); /* Add Intersection square image */ VBox intersectionPane = new VBox(); Label intersectionLabel = new Label("Intersection"); intersectionLabel.setPadding(new Insets(5, 5, 0, 30)); intersectionLabel.setFont(Font.font("Arial", FontWeight.SEMI_BOLD, 12)); Image intersectionImg = new Image("IntersectionX.png", 60, 60, true, false); intersectionImgView = new ImageView(intersectionImg); StackPane intersectionStackPane = new StackPane(intersectionImgView); intersectionStackPane.setPadding(new Insets(0, 10, 10, 10)); intersectionPane.getChildren().add(intersectionLabel); intersectionPane.getChildren().add(intersectionStackPane); sideComponents.getChildren().add(intersectionPane); /* Add RoadNS square image */ VBox roadNSPane = new VBox(); Label roadNSLabel = new Label("Road (North-South)"); roadNSLabel.setPadding(new Insets(5, 5, 0, 15)); roadNSLabel.setFont(Font.font("Arial", FontWeight.SEMI_BOLD, 12)); Image roadNSImg = new Image("RoadBackgroundNS.png", 60, 60, true, false); roadNSImgView = new ImageView(roadNSImg); StackPane roadNSStackPane = new StackPane(roadNSImgView); roadNSStackPane.setPadding(new Insets(0, 10, 10, 10)); roadNSPane.getChildren().add(roadNSLabel); roadNSPane.getChildren().add(roadNSStackPane); sideComponents.getChildren().add(roadNSPane); /* Add RoadEW square image */ VBox roadEWPane = new VBox(); Label roadEWLabel = new Label("Road (East-West)"); roadEWLabel.setPadding(new Insets(5, 5, 0, 15)); roadEWLabel.setFont(Font.font("Arial", FontWeight.SEMI_BOLD, 12)); Image roadEWImg = new Image("RoadBackgroundEW.png", 60, 60, true, false); roadEWImgView = new ImageView(roadEWImg); StackPane roadEWStackPane = new StackPane(roadEWImgView); roadEWStackPane.setPadding(new Insets(0, 10, 10, 10)); roadEWPane.getChildren().add(roadEWLabel); roadEWPane.getChildren().add(roadEWStackPane); sideComponents.getChildren().add(roadEWPane); /* Add Grass square image to empty out cells */ VBox grassPane = new VBox(); Label grassLabel = new Label("Grass (clear square)"); grassLabel.setPadding(new Insets(5, 5, 0, 15)); grassLabel.setFont(Font.font("Arial", FontWeight.SEMI_BOLD, 12)); Image grassImg = new Image("Grass.png", 60, 60, true, false); grassImgView = new ImageView(grassImg); StackPane grassStackPane = new StackPane(grassImgView); grassStackPane.setPadding(new Insets(0, 10, 10, 10)); grassPane.getChildren().add(grassLabel); grassPane.getChildren().add(grassStackPane); sideComponents.getChildren().add(grassPane); /* Add Save, Reset buttons */ VBox buttonsPane = new VBox(); buttonsPane.setPadding(new Insets(0, 0, 0, 10)); Label toolsLabel = new Label("Tools"); toolsLabel.setFont(Font.font("Arial", FontWeight.EXTRA_BOLD, 14)); toolsLabel.setPadding(new Insets(15, 5, 5, 35)); buttonsPane.getChildren().add(toolsLabel); Insets padding = new Insets(0, 0, 5, 0); Button saveButton = new Button("Save Map"); StackPane saveButtonPane = new StackPane(saveButton); saveButtonPane.setPadding(padding); saveButton.setStyle("-fx-base:Gold"); saveButton.setFont(Font.font("System Bold Italic", FontWeight.BOLD, 13)); buttonsPane.getChildren().add(saveButtonPane); Button resetButton = new Button("Reset Map"); resetButton.setStyle("-fx-base:Gold"); resetButton.setFont(Font.font("System Bold Italic", FontWeight.BOLD, 13)); StackPane resetButtonPane = new StackPane(resetButton); resetButtonPane.setPadding(padding); buttonsPane.getChildren().add(resetButtonPane); Button backButton = new Button("Go Back"); backButton.setStyle("-fx-base:Gold"); backButton.setFont(Font.font("System Bold Italic", FontWeight.BOLD, 13)); StackPane backButtonPane = new StackPane(backButton); backButtonPane.setPadding(padding); buttonsPane.getChildren().add(backButtonPane); sideComponents.getChildren().add(buttonsPane); Ticker.start(); /* Add click processing for Map grid squares */ for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Node current = getNodeFromIndex(i, j, mapGridPane); final int x = j; final int y = i; current.setOnMouseClicked( (MouseEvent click) -> { MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused()); MapMakerController.setCurrentFocused(ComponentType.MAP_SQUARE); current.requestFocus(); }); current .focusedProperty() .addListener( (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> { ComponentType previous = MapMakerController.getPreviousFocused(); if (previous == ComponentType.INTERSECTION) { addIntersection( x, y, map, mapGridGUIDecorator, mapGridPane, intersectionImgView); } else if (previous == ComponentType.ROADNS) { addRoadNS(x, y, map, mapGridGUIDecorator, mapGridPane, roadNSImgView); } else if (previous == ComponentType.ROADEW) { addRoadEW(x, y, map, mapGridGUIDecorator, mapGridPane, roadEWImgView); } else if (previous == ComponentType.GRASS) { addGrass(x, y, map, mapGridGUIDecorator, mapGridPane, grassImgView); } }); } } /* Add intersection icon click processing */ DropShadow ds = new DropShadow(15, Color.BLUE); intersectionImgView.setOnMouseClicked( click -> { MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused()); MapMakerController.setCurrentFocused(ComponentType.INTERSECTION); intersectionImgView.requestFocus(); }); intersectionImgView .focusedProperty() .addListener( (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> { if (newValue) intersectionImgView.setEffect(ds); else intersectionImgView.setEffect(null); }); /* Add roadNS icon click processing */ roadNSImgView.setOnMouseClicked( click -> { MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused()); MapMakerController.setCurrentFocused(ComponentType.ROADNS); roadNSImgView.requestFocus(); }); roadNSImgView .focusedProperty() .addListener( (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> { if (newValue) roadNSImgView.setEffect(ds); else roadNSImgView.setEffect(null); }); /* Add roadEW icon click processing */ roadEWImgView.setOnMouseClicked( click -> { MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused()); MapMakerController.setCurrentFocused(ComponentType.ROADEW); roadEWImgView.requestFocus(); }); roadEWImgView .focusedProperty() .addListener( (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> { if (newValue) roadEWImgView.setEffect(ds); else roadEWImgView.setEffect(null); }); /* Add grass icon click processing */ grassImgView.setOnMouseClicked( click -> { MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused()); MapMakerController.setCurrentFocused(ComponentType.GRASS); grassImgView.requestFocus(); }); grassImgView .focusedProperty() .addListener( (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> { if (newValue) grassImgView.setEffect(ds); else grassImgView.setEffect(null); }); /* Add save button functionality */ saveButton.setOnMouseClicked( click -> { TextInputDialog nameDialog = new TextInputDialog(); nameDialog.setTitle("Save Map"); nameDialog.setHeaderText( "Please provide a name for your map (no spaces or special characters).\nSaved maps go into the /maps directory of your working directory."); nameDialog.setContentText("File name"); Button btOk = (Button) nameDialog.getDialogPane().lookupButton(ButtonType.OK); TextField textfield = nameDialog.getEditor(); Platform.runLater(() -> textfield.requestFocus()); btOk.setDisable(true); textfield .textProperty() .addListener( ((observable, oldValue, newValue) -> { btOk.setDisable(newValue.trim().isEmpty()); })); Optional<String> result = nameDialog.showAndWait(); result.ifPresent( name -> { name = name.concat(".map"); try { Map finalMap = buildAndSaveMap(map); finalMap.saveMap(name); goBack(primaryStage); } catch (Exception e) { e.printStackTrace(); } }); }); resetButton.setOnMouseClicked( click -> { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Component component = map.getAtLocation(new Coordinate(x, y)); if (component instanceof Road || component instanceof Intersection) { addGrass(x, y, map, mapGridGUIDecorator, mapGridPane, grassImgView); } } } }); backButton.setOnMouseClicked( click -> { try { goBack(primaryStage); } catch (Exception e) { e.printStackTrace(); } }); borderPane.setRight(sideComponents); Scene scene = new Scene(borderPane); primaryStage.setScene(scene); primaryStage.centerOnScreen(); primaryStage.setResizable(false); }