title: Synchronizing events / data in java swing between many different classes
body: <p>My question is conceptual about synchronizing data and events in programming a gui. (This example shows batch state being the facilitator of taking classes that implement the same interface and dynamical updating cells in two different frames.This code is where I got my idea. )</p>
  
  <p>I am assuming that I will create new instances of this batch state object specifically in the classes where an event is triggered(panel)  and the reaction  to that event(another panel) . I will do this by adding the classes that need to communicate to the a list of bsListeners. Then call the batch state function like "setSelectedCell()" to iterate over each class to synchronize them.</p>
  
  <p><strong>The Problem</strong>
  This would work perfect if the object both shared the same arrayList but since they are both new instances they don't. I tried changing things to static and it is freaking out especially in the interface. Is this approach logical I am brand new to programming gui's? Sorry this is a novel.</p>
  
  <pre><code>interface BatchStateListener {
  
      public void valueChanged(Cell cell, String newValue);
  
      public void selectedCellChanged(Cell newSelectedCell)
  }
  
  class BatchState {
  
      private String[][] values;
      private Cell selectedCell;
      private List&lt;BatchStateListener&gt; listeners;
  
      public BatchState(int records, int fields) {
          values = new String[records][fields];
          selectedCell = null;
          listeners = new ArrayList&lt;BatchStateListener&gt;();
      }
  
      public void addListener(BatchStateListener l) {
          listeners.add(l);
      }
  
      public void setValue(Cell cell, String value) {
  
          values[cell.record][cell.field] = value;
  
          for (BatchStateListener l : listeners) {
              l.valueChanged(cell, value);
          }
      }
  
      public String getValue(Cell cell) {
          return values[cell.record][cell.field];
      }
  
      public void setSelectedCell(Cell selCell) {
  
          selectedCell = selCell;
  
          for (BatchStateListener l : listeners) {
              l.selectedCellChanged(selCell);
          }
      }
  
      public Cell getSelectedCell() {
          return selectedCell;
      }
  }
  </code></pre>