3

i receive float data from the network every 400 ms that i put in 4 arrays of float. I store those arrays in another array, so i have :

float[][] datas = {data1, data2, data3, data4};
FloatData floatData = new FloatData(datas);
model.addFloatData(floatData);

My model has a list of FloatData object and the FloatData object has the method :

float[] getFloatData(int index);

that returns the array of float that i want. This array is used to paint on a JPanel. So in the painComponent i do the following :

for(FloatData floatData : listOfFloatData) {
floatData.draw(g, index);
}

My question is what kind of list can i use for the listOfFloatData as it will be updated every 400 ms and read in the paintComponent method ? Also, i would like to know a convenient way to pass the listOfFloatData from the model to my view ? I was thinking about using a singleton object holding the listOfFloatData as this list will be used in several components ? Thank you.

LionO
  • 33
  • 2
  • are you having problems the way you did ? – woliveirajr Jul 27 '11 at 19:01
  • 1
    400ms is a fair amount of time for your computer. Have you had any sort of performance trouble using the standard Java List implementations, such as java.util.ArrayList, or are you trying to optimize your list before you know there's any performance problem? – Richard Campbell Jul 27 '11 at 19:09
  • Trying to optimize and have some advice on doing it a better way if there is. The time could also be 200 ms. I haven't tried it yet cause i don't really know yet how i will pass it to my view. – LionO Jul 27 '11 at 19:20

1 Answers1

2

Decouple the model from the view by storing your data in a subclass of AbstractTableModel. The flyweight pattern used by JTable is much more efficient at rendering, and you can modify your model as profiling warrants.

Addendum: If you collect data on another thread, using e.g. SwingWorker, you can publish() the data with very low latency, while your process() implementation updates the model on the Event Dispatch Thread. There's an example here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045