Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List for holding data

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.

like image 863
LionO Avatar asked May 19 '26 12:05

LionO


1 Answers

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.

like image 145
trashgod Avatar answered May 22 '26 02:05

trashgod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!