我正在尝试从另一个类中找到一种从我的主JavaFx类访问舞台的方法,所以我可以对它执行一些操作,但我不能,因为它作为参数传递,如下所示:
@Override
public void start(final Stage primaryStage) {
完整的WakiliProject
课程:
public class WakiliProject extends Application {
@Override
public void start(final Stage primaryStage) {
Group root = new Group();
StageDraggable.stageDraggable(root, primaryStage);
root.getChildren().addAll(mainContainer);
Scene scene = new Scene(root, 900, 654);
primaryStage.setScene(scene);
primaryStage.initStyle(StageStyle.UNDECORATED);
primaryStage.initStyle(StageStyle.TRANSPARENT);
primaryStage.setTitle("Wakili");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
如何在初始化舞台`public Stage newTryEMail;'之前从另一个类中捕获上述舞台primaryStage
并执行一些操作,如下所示:'
public class TryEMailController implements Initializable {
// Initializes the controller class.
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
public Stage newTryEMail;
public void newTryEMailStage() throws IOException {
newTryEMail = new Stage();
newTryEMail.initModality(Modality.WINDOW_MODAL);
newTryEMail.initOwner(AddNewEmailController.newComposeNewEmail);
Parent newTryEMailRoot = FXMLLoader.load(getClass().getResource("/wakiliproject/Forms/AddNew/NewEmail/TryEMailController.fxml"));
StageDraggable.stageDraggable(newTryEMailRoot, newTryEMail);
Scene newComposeNewEmailScene = new Scene(newTryEMailRoot, 590, 670);
newTryEMail.setScene(newComposeNewEmailScene);
newTryEMail.show();
}
}
来自另一个名为TryEMailController
的课程?
提前谢谢大家。
答案 0 :(得分:2)
试试这样:
public void newTryEMailStage(Stage primaryStage) throws IOException {
newTryEMail = primaryStage;
在开始方法中:
newTryEMailStage(primaryStage);
答案 1 :(得分:1)
将primaryStage引用从start()方法传递给要访问它的类。然后,您将在要访问它的类中存储对primaryStage对象的引用。如果您在start()方法运行之前尝试“捕获”对primaryStage对象的引用,那么我无法做到这一点。因此,相应地组织您的代码。