Boa noite senhores, encontro-me com um problema ao chamar a função no FXML criada para chamar outra view ao clicar no botão. Abaixo segue os códigos.
FXML Início (é o primeiro a ser chamado ao executar o programa)
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="classes.FXMLInicioController">
<children>
<Button layoutX="211.0" layoutY="302.0" mnemonicParsing="false" onAction="#chamadaDeView" prefHeight="25.0" prefWidth="179.0" text="Entrar" />
</children>
</AnchorPane>
Na linha do botão o NETBEANS detecta um erro ao chamar a função.
Controller do Início
package classes;
import java.awt.event.ActionEvent;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.stage.Stage;
import views.MenuPrincipalController;
/**
* FXML Controller class
*
* @author Hiago
*/
public class FXMLInicioController implements Initializable {
@FXML
public void chamadaDeView(ActionEvent e) throws Exception{
new MenuPrincipalController().start(new Stage());
}
/**
* Initializes the controller class.
* @param url
* @param rb
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
Classe para start:
package classes;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Inicio extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("FXMLInicio.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
FXML que deve ser chamado:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" fx:controller="views.MenuPrincipalController">
</AnchorPane>
Controller do mesmo:
package views;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class MenuPrincipalController implements Initializable {
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("FXMLMenuPrincipal.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("Sistema COPEX");
stage.setResizable(false);
stage.show();
}
@Override
public void initialize(URL location, ResourceBundle resources) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
Galera o link do GitHub é: https://github.com/hiagomf/COPEX