How to create multiple javafx controllers with different fxml files?

后端 未结 4 1934
無奈伤痛
無奈伤痛 2020-12-01 02:49

I\'ve been looking at some blogs and other stackoverflow questions, and I\'m not seeing a direct answer to my question. I am creating a javafx gui client and I want to have

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 03:43

    package javafxapplication11;
    import java.io.IOException;
    import java.net.URL;
    import java.util.ResourceBundle;
    import javafx.event.ActionEvent;
    import javafx.fxml.FXML;
    import javafx.fxml.FXMLLoader;
    import javafx.fxml.Initializable;
    import javafx.scene.Node;
    import javafx.scene.Parent;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.CheckBox;
    import javafx.stage.Stage;
    
    public class FXMLDocumentController implements Initializable {
    @FXML
    private CheckBox c1;
    
    @FXML
    private CheckBox c2;
    
    public void clicked1(ActionEvent e) throws IOException {
    Parent home_page_parent 
    =FXMLLoader.load(getClass().getResource("AddDcuFXML.fxml"));
     Scene home_page_scene = new Scene(home_page_parent);
     Stage app_stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
      app_stage.hide(); //optional
      app_stage.setScene(home_page_scene);
      app_stage.show();
       }
       public void clicked2(ActionEvent e) throws IOException {
       Parent home_page_parent 
        =FXMLLoader.load(getClass().getResource("ViewDCU.fxml"));
       Scene home_page_scene = new Scene(home_page_parent);
       Stage app_stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
        app_stage.hide(); //optional
          app_stage.setScene(home_page_scene);
             app_stage.show();
         }
          public void clicked3(ActionEvent e) throws IOException {
         Parent home_page_parent 
       =FXMLLoader.load(getClass().getResource("ViewDCU.fxml"));
        Scene home_page_scene = new Scene(home_page_parent);
        Stage app_stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
         app_stage.hide(); //optional
         app_stage.setScene(home_page_scene);
         app_stage.show();
          }
         @Override
           public void initialize(URL arg0, ResourceBundle arg1) {
            // TODO Auto-generated method stub
               } 
                   }
    

提交回复
热议问题