Netbeans:动作事件方法未在fxml中定义

时间:2018-03-23 10:56:35

标签: javafx scenebuilder

I have 2 buttons ,when click on JFXButton 'inscrire', anchorPane Login bring to Front if click on Login anchorPane SignUp bring to Front

我的问题是NetBeans调用了一个异常,即#handleButtonAction方法控制器没有在根组件上定义。



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

<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXPasswordField?>
<?import com.jfoenix.controls.JFXTextField?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>

<AnchorPane prefHeight="489.0" prefWidth="778.0" style="-fx-background-color: rgb(0, 0, 0,0);" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <AnchorPane layoutY="34.0" prefHeight="438.0" prefWidth="778.0" style="-fx-background-color: #fff; -fx-border-radius: 5em;">
         <children>
            <AnchorPane fx:id="PaneInscrire" layoutX="465.0" prefHeight="444.0" prefWidth="313.0" style="-fx-background-color: #ffffff;">
               <children>
                  <JFXTextField layoutX="69.0" layoutY="118.0" prefHeight="25.0" prefWidth="189.0" promptText="id" unFocusColor="#4d4d4d" />
                  <JFXTextField layoutX="68.0" layoutY="170.0" prefHeight="25.0" prefWidth="189.0" promptText="Nom et Prenom" />
                  <JFXTextField layoutX="68.0" layoutY="216.0" prefHeight="25.0" prefWidth="189.0" promptText="Email" />
                  <JFXTextField layoutX="68.0" layoutY="260.0" prefHeight="25.0" prefWidth="189.0" promptText="Ville" />
                  <JFXTextField layoutX="68.0" layoutY="307.0" prefHeight="25.0" prefWidth="189.0" promptText="MotdePass" />
                  <JFXButton contentDisplay="CENTER" graphicTextGap="7.0" layoutX="106.0" layoutY="373.0" prefHeight="25.0" prefWidth="114.0" style="-fx-background-color: #5316F5;" text="inscrire" textFill="WHITE" />
                  <Label layoutX="66.0" layoutY="32.0" prefHeight="53.0" prefWidth="196.0" style="-fx-background-color: #ffffgfg;" text="Inscruption" textFill="#5316f5">
                     <font>
                        <Font size="38.0" />
                     </font>
                  </Label>
               </children>
            </AnchorPane>
            <JFXButton fx:id="inscrire" layoutY="177.0" onAction="#handleButtonAction" prefHeight="45.0" prefWidth="84.0" text="Inscrire" textFill="#5316f5" />
            <JFXButton fx:id="sign" layoutY="222.0" onAction="#handleButtonAction" prefHeight="45.0" prefWidth="84.0" text="Login" textFill="#5316f5" />
            <AnchorPane fx:id="PaneSign" layoutX="465.0" prefHeight="444.0" prefWidth="313.0" style="-fx-background-color: #FFFFFF; -fx-background-radius: 5em;">
               <children>
                  <JFXPasswordField layoutX="55.0" layoutY="233.0" prefHeight="25.0" prefWidth="233.0" promptText="MotPass" />
                  <JFXButton contentDisplay="CENTER" graphicTextGap="7.0" layoutX="106.0" layoutY="344.0" prefHeight="35.0" prefWidth="131.0" style="-fx-background-color: #5316F5;" text="SignIn" textFill="WHITE" />
                  <JFXTextField layoutX="55.0" layoutY="170.0" prefHeight="25.0" prefWidth="233.0" promptText="Username" />
                  <Label layoutX="100.0" layoutY="37.0" prefHeight="96.0" prefWidth="144.0" style="-fx-background-color: #ffffgfg;" text="Login" textFill="#5316f5">
                     <font>
                        <Font size="44.0" />
                     </font>
                  </Label>
               </children>
            </AnchorPane>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

看起来你没有控制器属性。您需要添加一个控制器属性,以便您的视图可以与其控制器进行交互。  在关闭根元素的开始标记之前插入fx:controller="com.yourcompany.YourController"

示例:<AnchorPane ... fx:controller="com.yourcompany.YourController">

接下来,在您的控制器类中,确保您具有如下设置的功能:

@FXML
void handleButtonAction(ActionEvent e) {
    // Your logic goes here...
}

现在,当您通过FXML加载视图时,它应该能够与控制器类进行交互。