How do you create a new object in a javafx scene?


Question

I cannot seem to add a new object to my scene. Right now i have when you click on a green square it runs the method select and when you click on a button it runs the newcity method and is supposed to create a blue square. I have tried adding my rectangle to the parent but i always get errors. In the code below getChildren() in the City Class is underlined in red!

Here is my code:
Main Class:

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);
    }
}

MainControl Class:

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);
    }
}

City Class:

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
    }
}

Map1 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>

Please help
Thanks

1
2
7/16/2015 7:11:31 AM

Accepted Answer

I would suggest to create a class City which 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"));
    }

}

If you want to "connect" Methods from your FXML-Controller class to the FXML-File, you have to annotate them with @FXML in your Controller.

Here i have an example for you:

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 <Patrick.Ott@professional-webworkx.de>
 */
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);

    }
}

Because your FXML is shortend and you also didn't post you full i worked on the FXML-File you added to your Question, which follows below.

<?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>

I hope it will help you. If something is not clear, feel free to comment and ask ;)

Patrick

3
7/14/2014 10:55:14 AM

JavaFX fiddles around with objects behind the scenes. I do not know your exact error but I can assume that it is a null pointer exception relating to the variable selectnode. If you define this variable as public static then you can reference it statically instead of passing it. This should also resolve the issue of it becoming undefined.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon