GetText _ TextField (JavaFx)

0 respostas
java
Angelodsrocha

Estou tendo problemas para retornar o input do TextField no javaFX. O que poderia estar errado?

public class LifeTimeManagementControl extends Application {
Login login = new Login();
       
    @Override
    public void start(Stage primaryStage) {
        

        primaryStage.setTitle("Life Time Management");
        GridPane grid = new GridPane();
        grid.setAlignment(Pos.CENTER);
        grid.setHgap(10);
        grid.setVgap(10);
        grid.setPadding(new Insets(10, 10, 10, 10));
       // grid.setGridLinesVisible(true);
        
        final Text actiontarget = new Text();
        grid.add(actiontarget, 1, 6);
        
        Scene scene = new Scene(grid, 300, 250);
        primaryStage.setScene(scene);
        scene.getStylesheets().add(LifeTimeManagementControl.class.getResource("/login/login.css").toExternalForm());
        
        Text sceneTitle = new Text("Login");
        sceneTitle.setFont(Font.font("Calibri", 20));
        sceneTitle.setId("SceneTitle");
        
        grid.add(sceneTitle, 0, 0, 2, 1);
        
        Label loginLbl = new Label("Username: ");
        grid.add(loginLbl, 0, 1);

        Text pw = new Text("Password:");
        grid.add(pw, 0, 2);

        TextField usernameInput;
        usernameInput = new TextField();
        String usernameinput = usernameInput.getText();
        grid.add(usernameInput, 1, 1);
        
        
        PasswordField passwordInput = new PasswordField();
        grid.add(passwordInput, 1, 2);
        
        
        Button loginBtn = new Button("Sign in");
        loginBtn.setId("LoginBtn");
        HBox hbn = new HBox(10);
        hbn.setAlignment(Pos.BOTTOM_RIGHT);
        hbn.getChildren().add(loginBtn);
        grid.add(hbn, 1, 4);
        
        loginBtn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
             
                /*  try {
                    login.loginAction(usernameinput, pwInput);
                    actiontarget.setFill(Paint.valueOf("Blue"));
               actiontarget.setText("Button Pressed");
                } catch (SQLException ex) {
                    Logger.getLogger(LifeTimeManagementControl.class.getName()).log(Level.SEVERE, null, ex);
                }
               */
                System.out.println("Valor user: " + usernameinput + "\nValor PW: " + passwordInput);
            }
        });
        
        primaryStage.show();

    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

}
Criado 20 de novembro de 2016
Respostas 0
Participantes 1