question about keeping th
To: comp.lang.java.gui
Hello,
I have a question about keeping logic/processing code off of the GUI.
In a couple of other languages I'm familiar with, there is usually a
method called FindComponent which will iterate through a form and get
the component matching the name in the argument.
For example, in VS.NET lets say I have a grid (table) on a form, the
form represents one class. I then put the code for getting and
processing data in another class. After any processing occurs (and
the results are placed in a dataset), I need to bind the dataset to
the grid. But the grid doesn't have knowledge of where the dataset
came from... so how does the data get shoveled in there?
In the data processing class, there's a local variable of grid type
and it's gets bound to the grid in the form, like so (sorry about the
VB):
Class SomeClass
Sub doSomething(ByVal c As Component)
Dim localGridView as GridView
Dim localDataSet as DataSet
' MyGrid lives on Form1
localGridView = c.FindComponent("MyGrid")
localGridView.DataSource = localDataSet
' So even though the GUI hasn't a clue as to what is going on, the
current data is now displayed to the user.
localGridView.DataBind()
End Sub
End Class
Does Java have an equivalent of FindComponent, or a something similar
to the code snip above?
I'm using Java 6 here. I did try looking at c.getComponent() but
there's only one valid index... 0 and it represents the
javax.swing.JRootPane. Anything after 0 throws an index out of bounds
error. There are 3 JButtons and 1 JList on the panel. I want to add
some strings to the JList...
public class MyGUI() extends JFrame
{
GUIUtils u = new GUIUtils();
public MyGUI()
{
//
// snip
//
myButton.addActionListener (new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
try
{
u.doSomething(MyGUI.this);
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
});
}
and...
public class GUIUtils
{
public void doSometing(Container c) throws IOException
{
listModel = new DefaultListModel();
listModel.addElement(value);
// I want to put the listmodel in the JList now but how do I get
this code to know about the JList in MyGUI?
}
}
Suggestions are greatly appreciated.
Thanks!
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24