Making DataConnections using DataSources and DataListeners.

Initialize

All three Physlets embedded in this page communicate through the SDataSource and SDataListener interfaces.  In top applet, the DataGraph, two data series are acting as a listeners for the middle applet, the DataSource.  The bottom applet is also also listening to the middle applet.  Whenever the add button is pressed on the DataSource, a datum containing two numbers, x and y, is sent to all data listeners.    It is important to realize that any analytic function of x and y can be sent to the data listeners.  Analytic functions are specified when the DataConnection is made between a source and listener.  This is usually accomplished by the Physlet containing the data  using the makeDataConnection method of the Physlet containing the DataSource.

makeDataConnection(int sourceID,int listenerID,int series,String f_xy ,Sting g_xy ); 

Script Example

<script language="JavaScript"> 
function init(){
   document.DataGraph.clearSeries(1);
   document.DataGraph.setSeriesStyle(1,false,2); 
   document.DataGraph.setSeriesRGB(1,255,0,0);
   document.DataGraph.clearSeries(2);
   document.DataGraph.setSeriesStyle(2,true,0); 
   document.DataGraph.setSeriesRGB(2,0,255,0);  
   gid=document.DataGraph.getID();  // the ID of the DataGraph listener
   sid=document.DataSource.getID(); 
   lid=document.DataListener.getID(); // the ID of the listener applet 
   document.DataSource.removeDataConnections();
   document.DataSource.makeDataConnection(sid,gid,1,"n","x"); 
   document.DataSource.makeDataConnection(sid,gid,2,"n","y"); 
   document.DataSource.makeDataConnection(sid,lid,1,"n","y*y"); 
}
</script>