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

问题描述 投票:1回答:1

就像这个主题的对象一样,我试图保存从textField和passwordField插入的值,但没有成功 :(

实际上我使用的是eclipse和ScaneBuilder。

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

    <?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>

和下面的login.java文件。

//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);
            }

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

卢克

java javafx fxml scenebuilder
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.