0

I have two different FXML Files ViewOne.fxml-> ViewOneController and ViewTwo.fxml-> ViewTwoController.java.

On the first View are only 3 text fields and on the second View should draw a circle based on the Input from the first View.

My questions is how can I load both FXML Files on the same Scene and then later use the events to draw a circle ?

ViewOneController.java

public class ViewOneController {

    @FXML
    private HBox rootHBox;
    @FXML
    private TextField firstTextField;
    @FXML
    private TextField thirdTextField;
    @FXML
    private TextField secondTextField;

    @FXML
    void handleFirstTextField(ActionEvent event) {
    }

    @FXML
    void handleSecondTextField(ActionEvent event) {
    }

    @FXML
    void handleThirdTextField(ActionEvent event) {
    }
}

ViewOne.fxml

<HBox fx:id="rootHBox" maxHeight="-Infinity" maxWidth="-Infinity"   minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1"   fx:controller="exercise3Circles.ViewOneController">
   <children>
      <VBox prefHeight="400.0" prefWidth="243.0">
         <children>
            <AnchorPane prefHeight="401.0" prefWidth="243.0">
               <children>
                  <Label alignment="CENTER" layoutX="82.0" layoutY="44.0" text="View 1" textAlignment="CENTER">
                     <font>
                        <Font name="System Bold" size="20.0" />
                     </font>
                  </Label>
                  <Label layoutX="17.0" layoutY="120.0" text="X:" />
                  <TextField fx:id="firstTextField" layoutX="51.0" layoutY="115.0" onAction="#handleFirstTextField" />
                  <Label layoutX="17.0" layoutY="206.0" text="Y:" />
                  <TextField fx:id="thirdTextField" layoutX="51.0" layoutY="297.0" onAction="#handleThirdTextField" />
                  <Label layoutX="17.0" layoutY="302.0" text="R:" />
                  <TextField fx:id="secondTextField" layoutX="51.0" layoutY="201.0" onAction="#handleSecondTextField" />
               </children>
            </AnchorPane>
         </children>
      </VBox>
   </children>
</HBox>

ViewTwoController.java

public class ViewTwoController {

    @FXML
    private Label xLabel;

    @FXML
    private Label yLabel;

    @FXML
    private Label radiusLabel;
}

ViewTwo.fxml

<HBox alignment="CENTER_RIGHT" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="exercise3Circles.ViewTwoController">
   <children>
      <VBox alignment="CENTER_RIGHT" prefHeight="400.0" prefWidth="340.0">
         <children>
            <AnchorPane prefHeight="400.0" prefWidth="238.0">
           <children>
                  <Label layoutX="132.0" layoutY="44.0" text="View 2" textAlignment="CENTER">
                     <font>
                        <Font name="System Bold" size="20.0" />
                     </font>
                  </Label>
                  <Label layoutX="76.0" layoutY="356.0" text="X = 0" fx:id="xLabel" />
                  <Label fx:id="yLabel" layoutX="141.0" layoutY="356.0" text="Y = 0" />
                  <Label fx:id="radiusLabel" layoutX="208.0" layoutY="356.0" text="Radius = 0" />
               </children>
            </AnchorPane>
         </children>
      </VBox>
   </children>
</HBox>
Slaw
  • 37,820
  • 8
  • 53
  • 80
kannzzmm2
  • 131
  • 7
  • what's the problem, exactly? If it's parameter passing, see https://stackoverflow.com/questions/14187963/passing-parameters-javafx-fxml If something else, please clarify – kleopatra Apr 11 '19 at 09:33
  • 2
    For loading two FXML files, just load both of them and put them in a common parent. You could also create a third FXML file and [`fx:include`](https://openjfx.io/javadoc/12/javafx.fxml/javafx/fxml/doc-files/introduction_to_fxml.html#include_elements) the other two. – Slaw Apr 11 '19 at 09:36
  • Thank you @Slaw, it helped me a lot.. – kannzzmm2 Apr 11 '19 at 10:08

0 Answers0