Reputation: 35
I'm putting together a GUI with a couple of panels. In one panel there are components for the user to input various parameters. In another panel, there are buttons and a place to output a plot based on data generated using the user inputs.
I have all of the various pieces working independently now I'd just like them to talk to each other!!
When i hit one button, I would like to take all of user inputs and combine them to generate a data set and plot it. Another button then to write this same data to a file.
I have code to implement all the components individually, code to write data to a file and code to generate a plot from data. All of which works fine.
I thought that I could use the Action/ChangeEvents to take the parameters and
assign them to an ArrayList. Then use this arraylist to generate the data.
I'm finding it difficult to plan an approach to tackling this.
Currently I'm using get set methods in the event handlers to set parameter levels for a particular instance of the array list, I would like to pass this instance into another class to generate the data but don't know how to make it accessible.
I hope I have provided enought information here. If anyone has any thoughts on this they would be much appreciated.
Upvotes: 1
Views: 486
Reputation: 896
I think a structured way to tackle your issue is to apply the MVC pattern. Here is what I think a seminal article about Model-View-Controller (MVC) using Java.
Java SE Application Design With MVC by Robert Eckstein,
and here is another sample code.
As for taking the parameters from one panel and pass them on to the other panel, you can use the Command Pattern. What the pattern does is basically encapsulate all the information needed for a method to perform (an instance of a class, parameters, etc.) into one Command. This Command then can be passed around in the application, simplifying the way you execute the method.
A good book about Design Patterns, by the way, that I really love is Head First Design Pattern.
EDIT: I'd just like to add some links discussing about MVC and some other GUI architectures that I find useful:
Upvotes: 4
Reputation: 3093
This seems like a good case of application of MVC pattern: http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
Another good resource would be this book's second chapter: http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?ie=UTF8&qid=1334437965&sr=8-1
Upvotes: 1