简体   繁体   English

如何在java中的swing之间共享数据?

[英]How to share data among swing in java?

I have an swing app, that is used to perform a lot of calculations, making graphs, generate reports etc. In one JFrame, where the data is introduced by a JTable, the calculations are performed and return a Map with the info. 我有一个swing应用程序,用于执行大量计算,制作图表,生成报告等。在一个JFrame中,数据由JTable引入,执行计算并返回带有信息的Map。 Then in other JPanel, another window, this Map must be used in order to execute more calculations. 然后在另一个窗口的另一个窗口中,必须使用此Map才能执行更多计算。 This process must be executed around 6 or 7 window, and in different contexts, I mean not all are in the same JFrame. 这个过程必须在6或7窗口左右执行,在不同的上下文中,我的意思并不是所有都在同一个JFrame中。 The question is How can I share this data among the windows? 问题是如何在窗口之间共享这些数据? If I were working in a web app, I could put this data on a session scope or something like that and then take it. 如果我在一个Web应用程序中工作,我可以将这些数据放在会话范围或类似的东西上然后接受它。 But how can I perform this in a swing app? 但是我如何在摇摆应用程序中执行此操作? Thanks a lot!!! 非常感谢!!!

You can make the parent object hold all of the data and create setters and getters for it. 您可以使父对象保存所有数据并为其创建setter和getter。 Each window would then call get/set to get access to the data. 然后,每个窗口将调用get / set以访问数据。

You can also do some research into the "Model-View-Controller" pattern. 您还可以对“模型 - 视图 - 控制器”模式进行一些研究。 You have your parent object hold all of your data objects. 您的父对象包含所有数据对象。 Then you create windows that display the data using 'get' request methods from the parent, and controls that update the data with 'set' methods. 然后,您可以使用父项中的“get”请求方法创建显示数据的窗口,使用“set”方法创建更新数据的控件。

The MVC architecture is the answer. MVC架构就是答案。 Keep your data and your business logic in java classes that have nothing to do with swing and don't even know swing exists. 将您的数据和业务逻辑保存在与swing无关的java类中,甚至不知道swing存在。 Then pass this data around to your Swing code. 然后将这些数据传递给您的Swing代码。 The ActionListeners call the business logic that modifies the data. ActionListeners调用修改数据的业务逻辑。

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

相关问题 如何在Spark中的JavaRDD分区之间共享数据? - How to share data among JavaRDD partitions in Spark? 如何在本地网络上的多个主机之间状态共享我的Java应用程序的数据更改 - How to state-fully share my Java application's data changes among multiple hosts on a local network 单个功能中不同场景之间的Java共享数据 - java-Share data among different scenarios in a single feature Java:如何在多个应用程序之间共享通用应用程序/UI代码 - Java: How to share common application / UI code among several applications 如何在一组Java对象中共享一个名称? - How does one share a single name among a group of Java Objects? Java Servlet:如何在多个Servlet之间共享常见行为? - Java Servlets: How to share common behaviour among multiple servlets? 如何在多个Java应用程序之间共享连接池 - How to share connection pool among multiple Java applications 如何在 Java 中的多个线程之间共享公共日志文件 - How to share common log file among multiple threads in Java 如何在一个应用程序中的多个活动之间共享蓝牙接收的数据 - How to share Bluetooth received data among multiple activities in one application Java swing上的Facebook分享按钮 - Facebook share button on java swing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM