Events javafx CRUD buttons

0

I am developing a project (with javafx and scenebuilder) where I have to save the information of a stage in the database. The problem that appears to me is that the scene builder when I try to put the method that I made in the class does not lets put it on the button as if I did not detect it. Could you help me solve this problem?

@FXML
 private void enviar(ActionEvent event){
CRUDProveedor puente= new CRUDProveedor();
  int id_ped_prov= Integer.parseInt(id_ped_proveedor.getText());
  int id_proveedor=Integer.parseInt(id_prov.getText());
  String nombre_proveedor=nom_prov.getText();
  int telefono_provedor=Integer.parseInt(telefono_prov.getText());
  int direccion_proveedor=Integer.parseInt(direccion_prov.getText());
  int web_proveedor=Integer.parseInt(web_prov.getText());
  int email_proveedor=Integer.parseInt(email_prov.getText());

  puente.insertar(id_proveedor, id_ped_prov, id_ped_prov, nombre_proveedor, telefono_provedor, direccion_proveedor, nombre_proveedor, nombre_proveedor, nombre_proveedor);

}

    
asked by DANIEL FELIPE LOPEZ VARGAS 29.08.2017 в 07:43
source

2 answers

1

Sometimes the scenebuilder does what he wants and it does not work quite well, for this you can have the resource to modify the fxml by hand for example in your case

 <Button fx:id="btnenviar" onAction="#enviar">
 </Button>

another way, since you have the button with an id and you have declared it as an attribute @FXML, you can use it in the initialize:

btnenviar.setOnAction(new EventHandler<ActionEvent>() {
    public void handle(ActionEvent t) {
        CRUDProveedor puente= new CRUDProveedor();
        int id_ped_prov = Integer.parseInt(id_ped_proveedor.getText());
        int id_proveedor=Integer.parseInt(id_prov.getText());
        String nombre_proveedor=nom_prov.getText();
        int telefono_provedor=Integer.parseInt(telefono_prov.getText());
        int direccion_proveedor=Integer.parseInt(direccion_prov.getText());
        int web_proveedor=Integer.parseInt(web_prov.getText());
        int email_proveedor=Integer.parseInt(email_prov.getText());
        puente.insertar(id_proveedor, id_ped_prov, id_ped_prov, 
        nombre_proveedor, telefono_provedor, direccion_proveedor, 
        nombre_proveedor, nombre_proveedor, nombre_proveedor);

   }
});
    
answered by 13.03.2018 в 02:37
0

If you decide to use the button action through @FXML annotations, you need to:

  • In SceneBuilder, write the name of the method, in this case enviar , in the part intended for the On Action of the element in question (part marked with the black circle in the image).
  • In the code, write the annotation and the method, as you have it now:

    @FXML
    private void enviar(ActionEvent event){
      CRUDProveedor puente= new CRUDProveedor();
      int id_ped_prov= Integer.parseInt(id_ped_proveedor.getText());
      int id_proveedor=Integer.parseInt(id_prov.getText());
      String nombre_proveedor=nom_prov.getText();
      int telefono_provedor=Integer.parseInt(telefono_prov.getText());
      int direccion_proveedor=Integer.parseInt(direccion_prov.getText());
      int web_proveedor=Integer.parseInt(web_prov.getText());
      int email_proveedor=Integer.parseInt(email_prov.getText());
    
      puente.insertar(id_proveedor, id_ped_prov, id_ped_prov, nombre_proveedor, telefono_provedor, direccion_proveedor, nombre_proveedor, nombre_proveedor, nombre_proveedor);
    
    }
    
  • For more details you can consult: JavaFX 8 Event Handling Examples

        
    answered by 29.08.2017 в 18:05