[英]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.