控制器'MainController'没有事件槽'PassPhrase'

时间:2017-11-05 21:39:45

标签: java javafx

所以即时尝试创建Action事件,更改我的状态标签按钮上的文本,但我不断收到标题中列出的错误“控制器'MainController'没有事件插槽'PassPhrase',我是新来的不太确定该做什么。

此外,我希望输入我的passPhrase字段的文本保存在名为pass的变量下,如果有人可以仔细检查,我认为我做的正确吗?感谢。

This is my mainController

package application;

import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;

import javafx.fxml.FXML;

public class MainController {
@FXML
private Label lblStatus;


@FXML
private TextField txtPassPhrase;


String pass = txtPassPhrase.getText();

public void PassPhrase (ActionEvent event) {
    if (txtPassPhrase.getText().isEmpty()) {
        lblStatus.setText("You must Enter in Characters");
    } else {
        lblStatus.setText("Your PassPhrase has been accepted.");


    }
    }
}

这是我的passPhrase FXML

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

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>

<fx:root prefHeight="150.0" prefWidth="500.0" type="AnchorPane" 
xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" 
fx:controller="application.MainController">
   <children>
      <Button layoutX="210.0" layoutY="103.0" mnemonicParsing="false" 
onAction="#PassPhrase" text="Submit">
         <font>
            <Font size="18.0" />
         </font>
      </Button>
      <TextField fx:id="txtPassPhrase" layoutX="152.0" layoutY="56.0" 
prefHeight="39.0" prefWidth="199.0" promptText="Enter in a PassPhrase">
         <font>
            <Font size="18.0" />
         </font>
      </TextField>
      <Label fx:id="lblStatus" layoutX="80.0" layoutY="14.0" 
 prefHeight="17.0" prefWidth="423.0" text="Press submit once you enter in a 
PassPhrase" textFill="#e05858">
         <font>
            <Font size="18.0" />
         </font>
      </Label>
   </children>
</fx:root>

和我的主要班级

    package application;

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


public class Main extends Application {
@Override
public void start(Stage primaryStage) {
    try {

        Parent root = 
FXMLLoader.load(getClass().getResource("/application/passPhrase.fxml"));
        Scene scene = new Scene(root,400,400);




 scene.getStylesheets().add(getClass().getResource("application.css")
.toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

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

1 个答案:

答案 0 :(得分:0)

尝试将您的 <p id ="resultFromFile1" name = "results">No Results</p> 更改为`JavaFX&#39;进口。

imports