Как вы создаете новый объект в сцене javafx?

Кажется, я не могу добавить новый объект в свою сцену. Прямо сейчас у меня есть, когда вы нажимаете на зеленый квадрат, он запускает выбор метода, а когда вы нажимаете кнопку, он запускает метод newcity и должен создать синий квадрат. Я попытался добавить свой прямоугольник к родителю, но всегда получаю ошибки. В приведенном ниже коде getChildren() в классе City подчеркнуто красным!

Вот мой код:
Основной класс:

package application;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;


public class Main extends Application {
    public void start(Stage primaryStage) {
        try {
            Parent root = FXMLLoader.load(getClass().getResource("/fxml/Map1.fxml"));
            Scene scene = new Scene(root,576,352);
            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            primaryStage.setResizable(false);
            primaryStage.setScene(scene);
            primaryStage.setTitle("Map");
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Класс основного управления:

package application;

import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;

import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.shape.Rectangle;

public class MainControl implements Initializable {
    boolean selected = false;
    Node selectnode;
    public void initialize(URL arg0, ResourceBundle arg1) {
    };

    public void select(Event event) {
        selectnode = (Node) event.getSource();
        selected = true;
    }
    public void newcity(ActionEvent event){
        City ncity = new City();
        ncity.newcity(selectnode.getLayoutX(), selectnode.getLayoutY(),
                selectnode, event);
    }
}

Класс города:

package application;

import javafx.event.ActionEvent;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.shape.Rectangle;

public class City {
    public void newcity(double x,double y, Node n,ActionEvent event){

        Rectangle cityshape = new Rectangle(n.getLayoutX(), n.getLayoutY(),32, 32);
        Parent root = n.getParent();
        root.getChildren().add(cityshape); //getChildren() is underlined in red
    }
}

Карта 1 FXML:

    <?xml version="1.0" encoding="UTF-8"?>

    <?import javafx.scene.image.*?>
    <?import javafx.scene.*?>
    <?import javafx.scene.effect.*?>
    <?import javafx.scene.shape.*?>
    <?import javafx.scene.control.*?>
    <?import javafx.scene.text.*?>
    <?import java.lang.*?>
    <?import javafx.scene.layout.*?>

    <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="352.0" prefWidth="576.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainControl">
       <children>
  <TextField fx:id="textBox" layoutX="2.0" opacity="0.01" prefHeight="352.0" prefWidth="576.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
     <cursor>
        <Cursor fx:constant="DEFAULT" />
     </cursor>
     <effect>
        <ColorAdjust />
     </effect>
  </TextField>
  <Rectangle fx:id="tile1" fill="#26b522" height="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile20" fill="#26b522" height="32.0" layoutX="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile2" fill="#26b522" height="32.0" layoutX="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile3" fill="#26b522" height="32.0" layoutX="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile4" fill="#26b522" height="32.0" layoutX="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile5" fill="#26b522" height="32.0" layoutX="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile6" fill="#26b522" height="32.0" layoutX="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile7" fill="#26b522" height="32.0" layoutX="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile8" fill="#26b522" height="32.0" layoutX="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile9" fill="#26b522" height="32.0" layoutX="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile10" fill="#26b522" height="32.0" layoutX="320.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile101" fill="#26b522" height="32.0" layoutX="320.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile91" fill="#26b522" height="32.0" layoutX="288.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile81" fill="#26b522" height="32.0" layoutX="256.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile71" fill="#26b522" height="32.0" layoutX="224.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile61" fill="#26b522" height="32.0" layoutX="192.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile51" fill="#26b522" height="32.0" layoutX="160.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile41" fill="#26b522" height="32.0" layoutX="128.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile31" fill="#26b522" height="32.0" layoutX="96.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile21" fill="#26b522" height="32.0" layoutX="64.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile30" fill="#26b522" height="32.0" layoutX="32.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile11" fill="#26b522" height="32.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile102" fill="#26b522" height="32.0" layoutX="320.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile92" fill="#26b522" height="32.0" layoutX="288.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile82" fill="#26b522" height="32.0" layoutX="256.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile72" fill="#26b522" height="32.0" layoutX="224.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile62" fill="#26b522" height="32.0" layoutX="192.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile52" fill="#26b522" height="32.0" layoutX="160.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile42" fill="#26b522" height="32.0" layoutX="128.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile32" fill="#26b522" height="32.0" layoutX="96.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile22" fill="#26b522" height="32.0" layoutX="64.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile40" fill="#26b522" height="32.0" layoutX="32.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile12" fill="#26b522" height="32.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile103" fill="#26b522" height="32.0" layoutX="320.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile93" fill="#26b522" height="32.0" layoutX="288.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile83" fill="#26b522" height="32.0" layoutX="256.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile73" fill="#26b522" height="32.0" layoutX="224.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile63" fill="#26b522" height="32.0" layoutX="192.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile53" fill="#26b522" height="32.0" layoutX="160.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile43" fill="#26b522" height="32.0" layoutX="128.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile33" fill="#26b522" height="32.0" layoutX="96.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile23" fill="#26b522" height="32.0" layoutX="64.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile50" fill="#26b522" height="32.0" layoutX="32.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile13" fill="#26b522" height="32.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile104" fill="#26b522" height="32.0" layoutX="320.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile94" fill="#26b522" height="32.0" layoutX="288.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile84" fill="#26b522" height="32.0" layoutX="256.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile74" fill="#26b522" height="32.0" layoutX="224.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile64" fill="#26b522" height="32.0" layoutX="192.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile54" fill="#26b522" height="32.0" layoutX="160.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile44" fill="#26b522" height="32.0" layoutX="128.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile34" fill="#26b522" height="32.0" layoutX="96.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile24" fill="#26b522" height="32.0" layoutX="64.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile60" fill="#26b522" height="32.0" layoutX="32.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile14" fill="#26b522" height="32.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile105" fill="#26b522" height="32.0" layoutX="320.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile95" fill="#26b522" height="32.0" layoutX="288.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile85" fill="#26b522" height="32.0" layoutX="256.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile75" fill="#26b522" height="32.0" layoutX="224.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile65" fill="#26b522" height="32.0" layoutX="192.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile55" fill="#26b522" height="32.0" layoutX="160.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile45" fill="#26b522" height="32.0" layoutX="128.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile35" fill="#26b522" height="32.0" layoutX="96.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile25" fill="#26b522" height="32.0" layoutX="64.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile70" fill="#26b522" height="32.0" layoutX="32.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile15" fill="#26b522" height="32.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile106" fill="#26b522" height="32.0" layoutX="320.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile96" fill="#26b522" height="32.0" layoutX="288.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile86" fill="#26b522" height="32.0" layoutX="256.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile76" fill="#26b522" height="32.0" layoutX="224.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile66" fill="#26b522" height="32.0" layoutX="192.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile56" fill="#26b522" height="32.0" layoutX="160.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile46" fill="#26b522" height="32.0" layoutX="128.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile36" fill="#26b522" height="32.0" layoutX="96.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile26" fill="#26b522" height="32.0" layoutX="64.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile80" fill="#26b522" height="32.0" layoutX="32.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile16" fill="#26b522" height="32.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile107" fill="#26b522" height="32.0" layoutX="320.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile97" fill="#26b522" height="32.0" layoutX="288.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile87" fill="#26b522" height="32.0" layoutX="256.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile77" fill="#26b522" height="32.0" layoutX="224.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile67" fill="#26b522" height="32.0" layoutX="192.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile57" fill="#26b522" height="32.0" layoutX="160.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile47" fill="#26b522" height="32.0" layoutX="128.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile37" fill="#26b522" height="32.0" layoutX="96.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile27" fill="#26b522" height="32.0" layoutX="64.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile90" fill="#26b522" height="32.0" layoutX="32.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile17" fill="#26b522" height="32.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile108" fill="#26b522" height="32.0" layoutX="320.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile98" fill="#26b522" height="32.0" layoutX="288.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile88" fill="#26b522" height="32.0" layoutX="256.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile78" fill="#26b522" height="32.0" layoutX="224.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile68" fill="#26b522" height="32.0" layoutX="192.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile58" fill="#26b522" height="32.0" layoutX="160.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile48" fill="#26b522" height="32.0" layoutX="128.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile38" fill="#26b522" height="32.0" layoutX="96.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile28" fill="#26b522" height="32.0" layoutX="64.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile110" fill="#26b522" height="32.0" layoutX="32.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile18" fill="#26b522" height="32.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile109" fill="#26b522" height="32.0" layoutX="320.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile99" fill="#26b522" height="32.0" layoutX="288.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile89" fill="#26b522" height="32.0" layoutX="256.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile79" fill="#26b522" height="32.0" layoutX="224.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile69" fill="#26b522" height="32.0" layoutX="192.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile59" fill="#26b522" height="32.0" layoutX="160.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile49" fill="#26b522" height="32.0" layoutX="128.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile39" fill="#26b522" height="32.0" layoutX="96.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile29" fill="#26b522" height="32.0" layoutX="64.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile120" fill="#26b522" height="32.0" layoutX="32.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile19" fill="#26b522" height="32.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="r" arcHeight="15.0" arcWidth="15.0" fill="#ff1f1f" height="32.0" layoutX="256.0" layoutY="160.0" onMouseClicked="#move" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Label layoutX="495.0" layoutY="6.0" prefHeight="17.0" prefWidth="60.0" text="Moves left:" />
  <Label fx:id="movelabel" layoutX="553.0" layoutY="6.0" prefHeight="17.0" prefWidth="21.0" />
  <Button mnemonicParsing="false" onAction="#newcity" text="Found City" />
       </children>
    </AnchorPane>

Пожалуйста, помогите
Спасибо


person sazzy4o    schedule 14.07.2014    source источник
comment
Пожалуйста, отредактируйте свой вопрос и добавьте свой FXML.   -  person Patrick    schedule 14.07.2014
comment
Я сократил его и добавил его. Я думаю, что укороченная версия должна работать как другая. Спасибо   -  person sazzy4o    schedule 14.07.2014


Ответы (2)


Я бы предложил создать class City который extends Rectangle

import javafx.scene.Node;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Rectangle;


public class City extends Rectangle {

    public City(final Node node) {
        super(node.getLayoutX(), node.getLayoutY(), 32, 32);
        this.setFill(Paint.valueOf("BLUE"));
    }

}

Если вы хотите «подключить» методы из вашего класса FXML-контроллера к FXML-файлу, вы должны аннотировать их с помощью @FXML в своем контроллере.

Вот у меня есть для вас пример:

import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;

/**
 * FXML Controller class
 *
 * @author Patrick Ott <[email protected]>
 */
public class MapController implements Initializable {

    @FXML
    AnchorPane main;

    /**
     * Initializes the controller class.
     *
     * @param url
     * @param rb
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // do some initializing work here
    }

    @FXML
    public void movetest(MouseEvent event) {
        // your code for evaluating if move is possible..
        System.out.println("movetest()");
    }

    @FXML
    public void newcity(ActionEvent event) {
        // your code to create a new City
    }

    @FXML
    public void move(MouseEvent event) {
        Node node = (Node) event.getSource();
        City newCity = new City(node);
        main.getChildren().add(newCity);

    }
}

Поскольку ваш FXML сокращен, и вы также не опубликовали его полностью, я работал над FXML-файлом, который вы добавили к своему вопросу, который следует ниже.

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>

<AnchorPane fx:id="main" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="352.0" prefWidth="576.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="loadobject.MapController">
       <children>
  <TextField fx:id="textBox" layoutX="2.0" opacity="0.01" prefHeight="352.0" prefWidth="576.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
     <effect>
        <ColorAdjust />
     </effect>
  </TextField>
  <Rectangle fx:id="tile1" fill="#26b522" height="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile20" fill="#26b522" height="32.0" layoutX="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile2" fill="#26b522" height="32.0" layoutX="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile3" fill="#26b522" height="32.0" layoutX="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile4" fill="#26b522" height="32.0" layoutX="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile5" fill="#26b522" height="32.0" layoutX="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile6" fill="#26b522" height="32.0" layoutX="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile7" fill="#26b522" height="32.0" layoutX="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile8" fill="#26b522" height="32.0" layoutX="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile9" fill="#26b522" height="32.0" layoutX="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile10" fill="#26b522" height="32.0" layoutX="320.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile101" fill="#26b522" height="32.0" layoutX="320.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile91" fill="#26b522" height="32.0" layoutX="288.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile81" fill="#26b522" height="32.0" layoutX="256.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile71" fill="#26b522" height="32.0" layoutX="224.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile61" fill="#26b522" height="32.0" layoutX="192.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile51" fill="#26b522" height="32.0" layoutX="160.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile41" fill="#26b522" height="32.0" layoutX="128.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile31" fill="#26b522" height="32.0" layoutX="96.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile21" fill="#26b522" height="32.0" layoutX="64.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile30" fill="#26b522" height="32.0" layoutX="32.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile11" fill="#26b522" height="32.0" layoutY="32.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile102" fill="#26b522" height="32.0" layoutX="320.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile92" fill="#26b522" height="32.0" layoutX="288.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile82" fill="#26b522" height="32.0" layoutX="256.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile72" fill="#26b522" height="32.0" layoutX="224.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile62" fill="#26b522" height="32.0" layoutX="192.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile52" fill="#26b522" height="32.0" layoutX="160.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile42" fill="#26b522" height="32.0" layoutX="128.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile32" fill="#26b522" height="32.0" layoutX="96.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile22" fill="#26b522" height="32.0" layoutX="64.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile40" fill="#26b522" height="32.0" layoutX="32.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile12" fill="#26b522" height="32.0" layoutY="64.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile103" fill="#26b522" height="32.0" layoutX="320.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile93" fill="#26b522" height="32.0" layoutX="288.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile83" fill="#26b522" height="32.0" layoutX="256.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile73" fill="#26b522" height="32.0" layoutX="224.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile63" fill="#26b522" height="32.0" layoutX="192.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile53" fill="#26b522" height="32.0" layoutX="160.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile43" fill="#26b522" height="32.0" layoutX="128.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile33" fill="#26b522" height="32.0" layoutX="96.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile23" fill="#26b522" height="32.0" layoutX="64.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile50" fill="#26b522" height="32.0" layoutX="32.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile13" fill="#26b522" height="32.0" layoutY="96.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile104" fill="#26b522" height="32.0" layoutX="320.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile94" fill="#26b522" height="32.0" layoutX="288.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile84" fill="#26b522" height="32.0" layoutX="256.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile74" fill="#26b522" height="32.0" layoutX="224.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile64" fill="#26b522" height="32.0" layoutX="192.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile54" fill="#26b522" height="32.0" layoutX="160.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile44" fill="#26b522" height="32.0" layoutX="128.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile34" fill="#26b522" height="32.0" layoutX="96.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile24" fill="#26b522" height="32.0" layoutX="64.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile60" fill="#26b522" height="32.0" layoutX="32.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile14" fill="#26b522" height="32.0" layoutY="128.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile105" fill="#26b522" height="32.0" layoutX="320.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile95" fill="#26b522" height="32.0" layoutX="288.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile85" fill="#26b522" height="32.0" layoutX="256.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile75" fill="#26b522" height="32.0" layoutX="224.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile65" fill="#26b522" height="32.0" layoutX="192.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile55" fill="#26b522" height="32.0" layoutX="160.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile45" fill="#26b522" height="32.0" layoutX="128.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile35" fill="#26b522" height="32.0" layoutX="96.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile25" fill="#26b522" height="32.0" layoutX="64.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile70" fill="#26b522" height="32.0" layoutX="32.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile15" fill="#26b522" height="32.0" layoutY="160.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile106" fill="#26b522" height="32.0" layoutX="320.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile96" fill="#26b522" height="32.0" layoutX="288.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile86" fill="#26b522" height="32.0" layoutX="256.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile76" fill="#26b522" height="32.0" layoutX="224.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile66" fill="#26b522" height="32.0" layoutX="192.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile56" fill="#26b522" height="32.0" layoutX="160.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile46" fill="#26b522" height="32.0" layoutX="128.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile36" fill="#26b522" height="32.0" layoutX="96.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile26" fill="#26b522" height="32.0" layoutX="64.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile80" fill="#26b522" height="32.0" layoutX="32.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile16" fill="#26b522" height="32.0" layoutY="192.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile107" fill="#26b522" height="32.0" layoutX="320.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile97" fill="#26b522" height="32.0" layoutX="288.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile87" fill="#26b522" height="32.0" layoutX="256.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile77" fill="#26b522" height="32.0" layoutX="224.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile67" fill="#26b522" height="32.0" layoutX="192.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile57" fill="#26b522" height="32.0" layoutX="160.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile47" fill="#26b522" height="32.0" layoutX="128.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile37" fill="#26b522" height="32.0" layoutX="96.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile27" fill="#26b522" height="32.0" layoutX="64.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile90" fill="#26b522" height="32.0" layoutX="32.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile17" fill="#26b522" height="32.0" layoutY="224.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile108" fill="#26b522" height="32.0" layoutX="320.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile98" fill="#26b522" height="32.0" layoutX="288.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile88" fill="#26b522" height="32.0" layoutX="256.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile78" fill="#26b522" height="32.0" layoutX="224.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile68" fill="#26b522" height="32.0" layoutX="192.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile58" fill="#26b522" height="32.0" layoutX="160.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile48" fill="#26b522" height="32.0" layoutX="128.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile38" fill="#26b522" height="32.0" layoutX="96.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile28" fill="#26b522" height="32.0" layoutX="64.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile110" fill="#26b522" height="32.0" layoutX="32.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile18" fill="#26b522" height="32.0" layoutY="256.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile109" fill="#26b522" height="32.0" layoutX="320.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile99" fill="#26b522" height="32.0" layoutX="288.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile89" fill="#26b522" height="32.0" layoutX="256.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile79" fill="#26b522" height="32.0" layoutX="224.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile69" fill="#26b522" height="32.0" layoutX="192.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile59" fill="#26b522" height="32.0" layoutX="160.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile49" fill="#26b522" height="32.0" layoutX="128.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile39" fill="#26b522" height="32.0" layoutX="96.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile29" fill="#26b522" height="32.0" layoutX="64.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile120" fill="#26b522" height="32.0" layoutX="32.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="tile19" fill="#26b522" height="32.0" layoutY="288.0" onMouseClicked="#movetest" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Rectangle fx:id="r" arcHeight="15.0" arcWidth="15.0" fill="#ff1f1f" height="32.0" layoutX="256.0" layoutY="160.0" onMouseClicked="#move" stroke="BLACK" strokeType="INSIDE" width="32.0" />
  <Label layoutX="495.0" layoutY="6.0" prefHeight="17.0" prefWidth="60.0" text="Moves left:" />
  <Label fx:id="movelabel" layoutX="553.0" layoutY="6.0" prefHeight="17.0" prefWidth="21.0" />
  <Button layoutX="4.0" layoutY="6.0" mnemonicParsing="false" onAction="#newcity" text="Found City" />
       </children>
    </AnchorPane>

Я надеюсь, что это поможет вам. Если что-то непонятно, не стесняйтесь комментировать и спрашивать ;)

Патрик

person Patrick    schedule 14.07.2014
comment
Верно! Я использую JDK 1.8. - person Patrick; 14.07.2014
comment
Вы скопировали и вставили мой пример файла FXML? Если да, взгляните, пожалуйста, на атрибут fx:controller="..." и добавьте туда правильный пакет и имя контроллера. - person Patrick; 14.07.2014

JavaFX возится с объектами за кулисами. Я не знаю вашей точной ошибки, но могу предположить, что это исключение нулевого указателя, относящееся к переменной selectnode. Если вы определяете эту переменную как общедоступную статическую, вы можете ссылаться на нее статически, а не передавать ее. Это также должно решить проблему его неопределенности.

person Phil Bladen    schedule 14.07.2014
comment
Это не позволит exicuted getChildren() - person sazzy4o; 14.07.2014