Sounds like a job for Model View Controller - make model objects for the data you need for the electrical elements. You'll probably need to make another model object to consolidate the elements you want to display in the canvas, to collect them and perhaps hold information about connections. The canvas will be the view for this model. Then, you'll want to make another model object by implementing TableModel (or extending DefaultTableModel if you can) to hold all the electrical element model objects you want to appear in the table. A JTable will be the view of this model. Then you write controllers - these will be the listeners and event handlers that pass electrical element model objects between the canvas and the table, handle adding/deleting elements from the canvas or table, etc.
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Joined: May 18, 2008
Thanks. I am trying to implement this MVC philosophy and am quite some way down the path but I am not sure about passing information from one package to another. My JTable is in one package - tables and my drawing Canvas is in another - translation. I can input information into my JTable from the screen. However, I also want to be able to pass information into the JTable from the Drawing Canvas - this is where it all gets fuzzy.
This is the code for the popup Window to input data for the Generator from the Drawing Canvas
How do I get the information from here into this
I should press the EnterButton in the Generator Input Details class and then somehow get the information from the JTextFields and pass it on. It is this that I do not understand.
Please edit your code to get rid of the very long lines which make it very difficult to read. It is also impossible to try out because you are using a non-standard class (SpringUtilities) and not telling us where to get it from.
You would need to import the tables.GeneratorData class, and pushing the buttons would create a GeneratorData object.
Joined: May 18, 2008
Thank you for your help. Finally settled on the code below. The important method for passing of data is setGeneratorValues(); I import tables.*;
The code SpringUtilities is from the Java Sun Tutorial on Spring layouts.