简体   繁体   English

如何在javafx中的两个场景之间共享数据

[英]how to share data between two scenes in javafx

i would like to know how to move data in from one scene in javafx to another. 我想知道如何将数据从javafx中的一个场景移动到另一个场景。 I know that in server side programming like php you use SESSION, but I have no idea of desktop app 我知道在像PHP这样的服务器端编程中,您使用SESSION,但是我不知道桌面应用程序

Depending on what scope you want to enforce, you can choose one of the following (going from broad to narrow): 根据要强制执行的范围,可以选择以下选项之一(从宽到窄):

A) Use a singleton object that can be accessed globally and allow it to hold any information you require. A)使用可以全局访问的单例对象,并允许其保存您需要的任何信息。

B) Use a global/scoped event bus that allows listening for certain events. B)使用允许侦听某些事件的全局/作用域事件总线。 Attach the scene as a listener to the event bus. 将场景作为侦听器附加到事件总线。 The events then carry the information you need to handle the event. 然后,事件会携带处理事件所需的信息。

C) Track scenes manually and call methods directly on Scene instances for the smallest scope. C)手动跟踪场景并直接在最小范围内的Scene实例上调用方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM