JavaFX imput in textfields

1

I'm doing a program to calculate arrays, but I do not know how by an action for the "Confirm" button to get the values typed in the TextLabels (tl_lines and tl_columns) and move to the Int x and Int Y variables.

package matrizes;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;


public class FXMLDocumentController implements Initializable {


    @FXML
    private TextField tf_linhas;

    @FXML
    private Button btnTexto;

    @FXML
    private Button btnLC;

    @FXML
    private TextField tf_colunas;

    @FXML
    private final AnchorPane apMatriz = new AnchorPane();

      public void btnLC(ActionEvent e){


      }

    @Override
    public void initialize(URL url, ResourceBundle rb) {


        int x = 0;
        int y = 0;

        for(int i = 1; i < x+1; i++) {
            for(int j = 1; j < y+1; j++){
                Button btn = new Button();
                btn.setPrefWidth(40);
                btn.setLayoutX(i*45);
                btn.setLayoutY(j*30);
                btn.setText("a"+i+""+j);
            apMatriz.getChildren().add(btn);
            }
        }

        }

    }
    
asked by anonymous 20.03.2018 / 01:13

1 answer

0

The desired action can be implemented in the setOnMouseClicked method of the button, like this:

btn.setOnMouseClicked((event) -> {
    x = Integer.parseInt(tlLinhas.getText());
    y = Integer.parseInt(tlColunas.getText());
});

However, the variables x and y will have to become class variables. Java does not allow local variables to be used in an inner class, unless the variable is final.

    
06.04.2018 / 03:41