How to call another screen via MenuItem

1

I'm trying to call another screen (include) through a MenuItem, but it's not working.

At first, I can call my Login screen through Main.java, then I can also log in and call the Menu screen with a button.

I think the MenuItem method is different from Button, but I'm not sure how to do it.

 package application;

 import java.awt.event.ActionListener; import java.io.IOException;

 import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import
 javafx.scene.Scene; import javafx.scene.control.MenuItem; import
 javafx.stage.Stage;

 public class MenuController {

 @FXML private MenuItem menuItemFechar;

 @FXML private MenuItem menuItemIncluir;

 @FXML private MenuItem menuItemConsultar;

 @FXML private MenuItem menuItemAlterar;

 @FXML private MenuItem menuItemDeletar;

 @FXML public void logar(ActionListener action) {

   try {

    // alternar tela (fecha tela menu e abre tela incluir)  
    menuItemIncluir.getScene().getWindow().hide();

    FXMLLoader fxmlLoader = new FXMLLoader();  
    fxmlLoader.setLocation(getClass().getResource("Incluir.fxml"));  
    Scene scene = new Scene(fxmlLoader.load(), 600, 400);       
    Stage stage = new Stage();      
    stage.setTitle("Incluir");      
    stage.setScene(scene);      
    stage.show();   

   }  catch (IOException e) {       
     e.printStackTrace();   
   }

 } 

 }
    
asked by anonymous 26.02.2018 / 17:44

0 answers