I need to write monitors (tables, reports and graphs) that display information about groups of related variables in a simulation. My thought was to store the sources of the monitors information in an ArrayList. The sources will inevitably be different Classes (Stock, Flow or Auxiliary), however, and I dont see how to cast them properly so that I can retrieve the needed state information.
The following code works for a single Class. Is there a way it could be enhanced to handle several different Classes?
public class Mtr extends JInternalFrame { String name; private JTextArea ta; private JScrollPane sp; private ArrayList srcLst;
Mtr(String name, int x, int y, int hte, int wth) { super(name, false, false, true, true); srcLst = new ArrayList(); ta = new JTextArea(); sp = new JScrollPane(ta, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); add(sp); setBounds(x,y,wth,hte); }
Add a new method retrieveState() to the Stock, Flow and Auxiliary classes (actually, to their parent class, or to an interface they all implement). You then cast to the parent class / interface when you want to retrieve the state.
Thanks for replying. This is my first time on the forum, and its encouraging to get a reply so straight away.
I was curious if there might be some other way but, as you recognize, the problem calls for inheritance. The three mentioned elements are all Nodes in an interlinked network. I wrote a sketch of this solution that worked as you suggested. Plan to attack the larger problem tonight.
Not to ramble on, but by get my vote for best Brief Bio.