Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javaFX新手从密码和文本字段获取字符串_Java_Javafx_Fxml_Scenebuilder - Fatal编程技术网

javaFX新手从密码和文本字段获取字符串

javaFX新手从密码和文本字段获取字符串,java,javafx,fxml,scenebuilder,Java,Javafx,Fxml,Scenebuilder,与本主题的对象一样,我尝试保存从textField和passwordField插入的值,但未成功:( 实际上,我正在使用eclipse和ScaneBuilder 我已经创建了FXML文件(如下) 有人可以帮我解决我的问题吗?如果可能的话,请向我解释为什么eclipse会向我显示这个错误消息 提前感谢大家 lukeMoveString passwordDigit=passwordInput.getText().toString();和String usernameDigit=textInput.g

与本主题的对象一样,我尝试保存从textField和passwordField插入的值,但未成功:(

实际上,我正在使用eclipse和ScaneBuilder

我已经创建了FXML文件(如下)

有人可以帮我解决我的问题吗?如果可能的话,请向我解释为什么eclipse会向我显示这个错误消息 提前感谢大家


luke

Move
String passwordDigit=passwordInput.getText().toString();
String usernameDigit=textInput.getText().toString()
to
loginButton
方法。您在类本身中声明
passwordDigit
usernameDigit
,这意味着在用户按下登录按钮之前很久创建类时,它们只初始化一次。Move
String passwordDigit=passwordInput.getText().toString()
字符串usernameDigit=textInput.getText().toString();
loginButton
方法。您在类本身中声明
passwordDigit
usernameDigit
,这意味着在用户按下登录按钮之前很久创建类时,它们只初始化一次。
    <?xml version="1.0" encoding="UTF-8"?>

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


<AnchorPane prefHeight="300.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/11.0.1" fx:controller="application.Login">
   <children>
      <PasswordField fx:id= "passwordInput" layoutX="232.0" layoutY="174.0" prefHeight="25.0" prefWidth="267.0" />
      <TextField fx:id= "textInput" layoutX="232.0" layoutY="75.0" prefHeight="26.0" prefWidth="267.0" />
      <ButtonBar layoutX="232.0" layoutY="246.0" prefHeight="40.0" prefWidth="267.0">
        <buttons>
          <Button  mnemonicParsing="false" onAction="#resetPWD" text="Reset PWD" />
            <Button mnemonicParsing="false" onAction="#exitLogin" text="Exit" />
            <Button mnemonicParsing="false" onAction="#loginButton" text="Login" />
        </buttons>
      </ButtonBar>
      <Label layoutX="57.0" layoutY="72.0" prefHeight="25.0" prefWidth="131.0" text="Username:">
         <font>
            <Font size="24.0" />
         </font>
      </Label>
      <Label layoutX="57.0" layoutY="174.0" prefHeight="25.0" prefWidth="131.0" text="Password:">
         <font>
            <Font size="24.0" />
         </font>
      </Label>
   </children>
</AnchorPane>
//prelevo la stringa inserita nel campo TextField
            @FXML TextField passwordInput;
            String passwordDigit = passwordInput.getText().toString();
            @FXML TextField textInput;
            String usernameDigit = textInput.getText().toString();


            public void loginButton(ActionEvent actionEvent) {
                   //if pwd and user are ok open a new scane and in same time close this one
                System.out.println(passwordDigit);
                System.out.println(usernameDigit);
            }


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