Search code examples
javaswinguser-interfacedata-transfer-objects

How to transfer data as a single object from one GUI to another?


We need to transfer multiple data objects like String, int, float, etc from one GUI (JFrame, JInternalFrame, etc) to another GUI. We can tranfer them by using parameters in the constructors or share the data through a singleton class.

However, my question is how to pack multiple data objects into a single object and pass them as a single parameter between GUIs in Java Swing? In Android, we can do that using Bundle objects. Similarly, is there any such object in Java/Swing which can be used?


Solution

  • You have numerous options, however the two most likely to meet your needs would either be a custom Object or a Map. A custom object would have fields for each piece of information you need to transfer. See here for more information.