I've got a problem with my JavaFX 3D application. My application creates a grid consisting of different boxes. The data used for the boxes are from the harry potter books, which are transferred to nodes and then to boxes. Every box symbolizes one character. Now I want to add an event, that when a box is clicked application a window should open to show, which character it is and some other data.
"for (Book book : books) {
Node bookNode = new Node();
bookNode.setType(NodeType.BOOK);
bookNode.setName(book.getName());
bookNode.setMetric(getMetricFromPrimaryInt(book.getPages(),overallPages));
for (Chapter chapter : book.chapters) {
Node chapterNode = new Node();
chapterNode.setType(NodeType.CHAPTER);
chapterNode.setName(chapter.getName());
chapterNode.setMetric(getMetricFromPrimaryInt(chapter.getPages(), book.getPages()));
for (String character : chapter.characters) {
Node characterNode = new Node();
characterNode.setType(NodeType.CHARACTER);
characterNode.setName(character);
characterNode.setMetric(getMetricFromPrimaryInt(1, chapter.characters.length));
//Das neue child node dem parent hinzufügen
chapterNode.extendChildren(characterNode);
}
//Das neue child node dem parent hinzufügen
bookNode.extendChildren(chapterNode);
}"
. . . "for (Node chars: chapt.getChildren()) { double height = rnd.nextDouble() * 500;
Box box = new Box(chars.getHeight(), height, chars.getWidth());
// color
PhongMaterial mat = new PhongMaterial();
mat.setDiffuseColor(randomColor());
box.setMaterial(mat);
// location
box.setLayoutY(-height * 0.5);
box.setTranslateX(xStart-(chars.getHeight()/2));
box.setTranslateZ(yStart-(chars.getWidth()/2));
grid.getChildren().addAll(box);
Boxliste.add(box);
}"
My problem now is: How do I differentiate which box got clicked, because I need the box to get the characterdata and then display it. Hope it's clear what I mean.